summaryrefslogtreecommitdiff
path: root/checkout-index.c
diff options
context:
space:
mode:
authorLibravatar Johannes Schindelin <Johannes.Schindelin@gmx.de>2006-05-07 00:02:53 +0200
committerLibravatar Junio C Hamano <junkio@cox.net>2006-05-06 21:34:32 -0700
commitbe65e7d9fbd3ae6fc097cedade2afe39805fcf4e (patch)
treea9d0e6f6d4fc4a75eecdeafc20cf60d9b94883ee /checkout-index.c
parentt1300-repo-config: two new config parsing tests. (diff)
downloadtgif-be65e7d9fbd3ae6fc097cedade2afe39805fcf4e.tar.xz
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 'checkout-index.c')
-rw-r--r--checkout-index.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/checkout-index.c b/checkout-index.c
index 0b9cabc61c..cc3a745c14 100644
--- a/checkout-index.c
+++ b/checkout-index.c
@@ -277,7 +277,7 @@ int main(int argc, char **argv)
die("git-checkout-index: don't mix '--stdin' and explicit filenames");
p = prefix_path(prefix, prefix_length, arg);
checkout_file(p);
- if (p != arg)
+ if (p < arg || p > arg + strlen(arg))
free((char*)p);
}
@@ -299,7 +299,7 @@ int main(int argc, char **argv)
path_name = buf.buf;
p = prefix_path(prefix, prefix_length, path_name);
checkout_file(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);