@matheusbsbs / matheus-bagliano / commits / 806d13b1cc
Fork 0

update-index: refuse to add working tree items beyond symlinks

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>

Junio C Hamano committed Aug 4, 2008 at 00:51 UTC 806d13b1ccdbdde4bbdfb96902791c4b7ed125f6
2 files changed +24 -1
builtin-update-index.c
+4 -1
@@ -194,6 +194,10 @@ static int process_path(const char *path)
194 int len;
195 struct stat st;
196
197 + len = strlen(path);
198 + if (has_symlink_leading_path(len, path))
199 + return error("'%s' is beyond a symbolic link", path);
200 +
201 /*
202 * First things first: get the stat information, to decide
203 * what to do about the pathname!
@@ -201,7 +205,6 @@ static int process_path(const char *path)
205 if (lstat(path, &st) < 0)
206 return process_lstat_error(path, errno);
207
204 - len = strlen(path);
208 if (S_ISDIR(st.st_mode))
209 return process_directory(path, len, &st);
210
t/t0055-beyond-symlinks.sh new
+20
@@ -0,0 +1,20 @@
1 +#!/bin/sh
2 +
3 +test_description='update-index refuses to add beyond symlinks'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success setup '
8 + >a &&
9 + mkdir b &&
10 + ln -s b c &&
11 + >c/d &&
12 + git update-index --add a b/d
13 +'
14 +
15 +test_expect_success 'update-index --add beyond symlinks' '
16 + test_must_fail git update-index --add c/d &&
17 + ! ( git ls-files | grep c/d )
18 +'
19 +
20 +test_done