Skip to content

Commit

Permalink
update-index: refuse to add working tree items beyond symlinks
Browse files Browse the repository at this point in the history
When "sym" is a symbolic link that is inside the working tree, and it
points at a directory "dir" that has "path" in it, "update-index --add
sym/path" used to mistakenly add "sym/path" as if "sym" were a normal
directory.

"git apply", "git diff" and "git merge" have been taught about this issue
some time ago, but "update-index" and "add" have been left ignorant for
too long.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
gitster committed Aug 5, 2008
1 parent fba5279 commit 806d13b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion builtin-update-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,17 @@ static int process_path(const char *path)
int len;
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
* what to do about the pathname!
*/
if (lstat(path, &st) < 0)
return process_lstat_error(path, errno);

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

Expand Down
20 changes: 20 additions & 0 deletions t/t0055-beyond-symlinks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

test_description='update-index refuses 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_done

0 comments on commit 806d13b

Please sign in to comment.