mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
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>
This commit is contained in:
parent
bd886fd3ea
commit
be65e7d9fb
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -594,7 +594,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;
|
||||
|
@ -750,7 +750,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);
|
||||
|
|
Loading…
Reference in a new issue