summaryrefslogtreecommitdiff
path: root/builtin-update-index.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-08-04 00:51:42 -0700
committerJunio C Hamano <gitster@pobox.com>2008-08-04 23:31:23 -0700
commit806d13b1ccdbdde4bbdfb96902791c4b7ed125f6 (patch)
tree139db78f9efdb5f588c1b504b0dc8700d9d9039c /builtin-update-index.c
parentfba5279db904aa49bb75bb31614571b9b6d75b33 (diff)
downloadgit-806d13b1ccdbdde4bbdfb96902791c4b7ed125f6.tar.gz
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>
Diffstat (limited to 'builtin-update-index.c')
-rw-r--r--builtin-update-index.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/builtin-update-index.c b/builtin-update-index.c
index 38eb53ccba..434cb8e4a0 100644
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
@@ -194,6 +194,10 @@ 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!
@@ -201,7 +205,6 @@ static int process_path(const char *path)
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);