diff options
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | 2006-05-07 00:02:53 +0200 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-05-06 21:36:24 -0700 |
commit | 0cc9e70c4c9adb3e79b4a492f2f989c611d85966 (patch) | |
tree | 2e23e49ac67b628e433a1b518f9d312b17ab23ed /update-index.c | |
parent | 22293b9c41778bb60f3b07355e1b8e421a503702 (diff) | |
download | git-0cc9e70c4c9adb3e79b4a492f2f989c611d85966.tar.gz |
Fix users of prefix_path() to free() only when necessary
Unfortunately, prefix_path() sometimes returns a newly xmalloc()ed buffer,
and in other cases it returns a substring!
For example, when calling
git update-index ./hello.txt
prefix_path() returns "hello.txt", but does not allocate a new buffer. The
original code only checked if the result of prefix_path() was different from
what was passed in, and thusly trigger a segmentation fault.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'update-index.c')
-rw-r--r-- | update-index.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/update-index.c b/update-index.c index 184b2526da..3d7e02db2c 100644 --- a/update-index.c +++ b/update-index.c @@ -382,7 +382,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length) die("Unable to process file %s", path); report("add '%s'", path); free_return: - if (p != path) + if (p < path || p > path + strlen(path)) free((char*)p); } @@ -596,7 +596,7 @@ static int do_unresolve(int ac, const char **av, const char *arg = av[i]; const char *p = prefix_path(prefix, prefix_length, arg); err |= unresolve_one(p); - if (p != arg) + if (p < arg || p > arg + strlen(arg)) free((char*)p); } return err; @@ -610,7 +610,7 @@ static int do_reupdate(int ac, const char **av, */ int pos; int has_head = 1; - char **pathspec = get_pathspec(prefix, av + 1); + const char **pathspec = get_pathspec(prefix, av + 1); if (read_ref(git_path("HEAD"), head_sha1)) /* If there is no HEAD, that means it is an initial @@ -802,7 +802,7 @@ int main(int argc, const char **argv) update_one(p, NULL, 0); if (set_executable_bit) chmod_path(set_executable_bit, p); - if (p != path_name) + if (p < path_name || p > path_name + strlen(path_name)) free((char*) p); if (path_name != buf.buf) free(path_name); |