mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
prefer git_pathdup to git_path in some possibly-dangerous cases
Because git_path uses a static buffer that is shared with
calls to git_path, mkpath, etc, it can be dangerous to
assign the result to a variable or pass it to a non-trivial
function. The value may change unexpectedly due to other
calls.
None of the cases changed here has a known bug, but they're
worth converting away from git_path because:
1. It's easy to use git_pathdup in these cases.
2. They use constructs (like assignment) that make it
hard to tell whether they're safe or not.
The extra malloc overhead should be trivial, as an
allocation should be an order of magnitude cheaper than a
system call (which we are clearly about to make, since we
are constructing a filename). The real cost is that we must
remember to free the result.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
77b9b1d13a
commit
fcd12db6af
@@ -164,7 +164,7 @@ static void send_strbuf(const char *type, struct strbuf *buf)
|
||||
|
||||
static void send_local_file(const char *the_type, const char *name)
|
||||
{
|
||||
const char *p = git_path("%s", name);
|
||||
char *p = git_pathdup("%s", name);
|
||||
size_t buf_alloc = 8192;
|
||||
char *buf = xmalloc(buf_alloc);
|
||||
int fd;
|
||||
@@ -191,6 +191,7 @@ static void send_local_file(const char *the_type, const char *name)
|
||||
}
|
||||
close(fd);
|
||||
free(buf);
|
||||
free(p);
|
||||
}
|
||||
|
||||
static void get_text_file(char *name)
|
||||
|
||||
Reference in New Issue
Block a user