Merge branch 'jc/add-stop-at-symlink'

* jc/add-stop-at-symlink:
  add: refuse to add working tree items beyond symlinks
  update-index: refuse to add working tree items beyond symlinks
maint
Junio C Hamano 2008-08-20 23:42:18 -07:00
commit 4a871de896
4 changed files with 45 additions and 3 deletions

View File

@ -153,6 +153,16 @@ static const char **validate_pathspec(int argc, const char **argv, const char *p
{ {
const char **pathspec = get_pathspec(prefix, argv); const char **pathspec = get_pathspec(prefix, argv);


if (pathspec) {
const char **p;
for (p = pathspec; *p; p++) {
if (has_symlink_leading_path(strlen(*p), *p)) {
int len = prefix ? strlen(prefix) : 0;
die("'%s' is beyond a symbolic link", *p + len);
}
}
}

return pathspec; return pathspec;
} }


@ -278,7 +288,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
fprintf(stderr, "Maybe you wanted to say 'git add .'?\n"); fprintf(stderr, "Maybe you wanted to say 'git add .'?\n");
return 0; return 0;
} }
pathspec = get_pathspec(prefix, argv); pathspec = validate_pathspec(argc, argv, prefix);


/* /*
* If we are adding new files, we need to scan the working * If we are adding new files, we need to scan the working

View File

@ -194,6 +194,10 @@ static int process_path(const char *path)
int len; int len;
struct stat st; struct stat st;


len = strlen(path);
if (has_symlink_leading_path(len, path))
return error("'%s' is beyond a symbolic link", path);

/* /*
* First things first: get the stat information, to decide * First things first: get the stat information, to decide
* what to do about the pathname! * what to do about the pathname!
@ -201,7 +205,6 @@ static int process_path(const char *path)
if (lstat(path, &st) < 0) if (lstat(path, &st) < 0)
return process_lstat_error(path, errno); return process_lstat_error(path, errno);


len = strlen(path);
if (S_ISDIR(st.st_mode)) if (S_ISDIR(st.st_mode))
return process_directory(path, len, &st); return process_directory(path, len, &st);



6
dir.c
View File

@ -727,8 +727,12 @@ static void free_simplify(struct path_simplify *simplify)


int read_directory(struct dir_struct *dir, const char *path, const char *base, int baselen, const char **pathspec) int read_directory(struct dir_struct *dir, const char *path, const char *base, int baselen, const char **pathspec)
{ {
struct path_simplify *simplify = create_simplify(pathspec); struct path_simplify *simplify;


if (has_symlink_leading_path(strlen(path), path))
return dir->nr;

simplify = create_simplify(pathspec);
read_directory_recursive(dir, path, base, baselen, 0, simplify); read_directory_recursive(dir, path, base, baselen, 0, simplify);
free_simplify(simplify); free_simplify(simplify);
qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name); qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name);

25
t/t0055-beyond-symlinks.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/sh

test_description='update-index and add refuse to add beyond symlinks'

. ./test-lib.sh

test_expect_success setup '
>a &&
mkdir b &&
ln -s b c &&
>c/d &&
git update-index --add a b/d
'

test_expect_success 'update-index --add beyond symlinks' '
test_must_fail git update-index --add c/d &&
! ( git ls-files | grep c/d )
'

test_expect_success 'add beyond symlinks' '
test_must_fail git add c/d &&
! ( git ls-files | grep c/d )
'

test_done