diff options
author | Alex Riesen <raa.lkml@gmail.com> | 2008-10-26 23:07:24 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-10-26 22:10:28 -0700 |
commit | 94cc355287a7efc3eda76af6ae31f503a1ac098b (patch) | |
tree | 1e074ff609f880d031f25f5866dec1cad5eb6c3a /sha1_name.c | |
parent | 108bebeab31881654b7b0f1b5b393a6655d74d3f (diff) | |
download | git-94cc355287a7efc3eda76af6ae31f503a1ac098b.tar.gz |
Fix mkpath abuse in dwim_ref and dwim_log of sha1_name.c
Otherwise the function sometimes fail to resolve obviously correct
refnames, because the string data pointed to by "str" argument were
reused.
The change in dwim_log does not fix anything, just optimizes away
strcpy code as the path can be created directly in the available
buffer.
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r-- | sha1_name.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/sha1_name.c b/sha1_name.c index 4fb77f8863..75a5a7e96f 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -245,11 +245,13 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref) *ref = NULL; for (p = ref_rev_parse_rules; *p; p++) { + char fullref[PATH_MAX]; unsigned char sha1_from_ref[20]; unsigned char *this_result; this_result = refs_found ? sha1_from_ref : sha1; - r = resolve_ref(mkpath(*p, len, str), this_result, 1, NULL); + mksnpath(fullref, sizeof(fullref), *p, len, str); + r = resolve_ref(fullref, this_result, 1, NULL); if (r) { if (!refs_found++) *ref = xstrdup(r); @@ -272,7 +274,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log) char path[PATH_MAX]; const char *ref, *it; - strcpy(path, mkpath(*p, len, str)); + mksnpath(path, sizeof(path), *p, len, str); ref = resolve_ref(path, hash, 1, NULL); if (!ref) continue; |