@matheusbsbs / matheus-bagliano / commits / 94cc355287
Fork 0

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>

Alex Riesen committed Oct 26, 2008 at 23:07 UTC 94cc355287a7efc3eda76af6ae31f503a1ac098b
1 file changed +4 -2
sha1_name.c
+4 -2
@@ -245,11 +245,13 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
245
246 *ref = NULL;
247 for (p = ref_rev_parse_rules; *p; p++) {
248 + char fullref[PATH_MAX];
249 unsigned char sha1_from_ref[20];
250 unsigned char *this_result;
251
252 this_result = refs_found ? sha1_from_ref : sha1;
252 - r = resolve_ref(mkpath(*p, len, str), this_result, 1, NULL);
253 + mksnpath(fullref, sizeof(fullref), *p, len, str);
254 + r = resolve_ref(fullref, this_result, 1, NULL);
255 if (r) {
256 if (!refs_found++)
257 *ref = xstrdup(r);
@@ -272,7 +274,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
274 char path[PATH_MAX];
275 const char *ref, *it;
276
275 - strcpy(path, mkpath(*p, len, str));
277 + mksnpath(path, sizeof(path), *p, len, str);
278 ref = resolve_ref(path, hash, 1, NULL);
279 if (!ref)
280 continue;