add: refuse to add working tree items beyond symlinks
This is the same fix for the issue of adding "sym/path" when "sym" is a symblic link that points at a directory "dir" with "path" in it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 4, 2008 at 00:52 UTC
725b06050a083474e240a2436121e0a80bb9f175
3 files changed
+22
-3
builtin-add.c
+11
-1
@@ -153,6 +153,16 @@ static const char **validate_pathspec(int argc, const char **argv, const char *p
153
{
154
const char **pathspec = get_pathspec(prefix, argv);
155
156
+ if (pathspec) {
157
+ const char **p;
158
+ for (p = pathspec; *p; p++) {
159
+ if (has_symlink_leading_path(strlen(*p), *p)) {
160
+ int len = prefix ? strlen(prefix) : 0;
161
+ die("'%s' is beyond a symbolic link", *p + len);
162
+ }
163
+ }
164
+ }
165
+
166
return pathspec;
167
}
168
@@ -278,7 +288,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
288
fprintf(stderr, "Maybe you wanted to say 'git add .'?\n");
289
return 0;
290
}
281
- pathspec = get_pathspec(prefix, argv);
291
+ pathspec = validate_pathspec(argc, argv, prefix);
292
293
/*
294
* If we are adding new files, we need to scan the working
dir.c
+5
-1
@@ -727,8 +727,12 @@ static void free_simplify(struct path_simplify *simplify)
727
728
int read_directory(struct dir_struct *dir, const char *path, const char *base, int baselen, const char **pathspec)
729
{
730
- struct path_simplify *simplify = create_simplify(pathspec);
730
+ struct path_simplify *simplify;
731
732
+ if (has_symlink_leading_path(strlen(path), path))
733
+ return dir->nr;
734
+
735
+ simplify = create_simplify(pathspec);
736
read_directory_recursive(dir, path, base, baselen, 0, simplify);
737
free_simplify(simplify);
738
qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name);
t/t0055-beyond-symlinks.sh
+6
-1
@@ -1,6 +1,6 @@
1
#!/bin/sh
2
3
-test_description='update-index refuses to add beyond symlinks'
3
+test_description='update-index and add refuse to add beyond symlinks'
4
5
. ./test-lib.sh
6
@@ -17,4 +17,9 @@ test_expect_success 'update-index --add beyond symlinks' '
17
! ( git ls-files | grep c/d )
18
'
19
20
+test_expect_success 'add beyond symlinks' '
21
+ test_must_fail git add c/d &&
22
+ ! ( git ls-files | grep c/d )
23
+'
24
+
25
test_done