Skip to content

Commit 94cc355

Browse files
raalkmlgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 108bebe commit 94cc355

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sha1_name.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,13 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
245245

246246
*ref = NULL;
247247
for (p = ref_rev_parse_rules; *p; p++) {
248+
char fullref[PATH_MAX];
248249
unsigned char sha1_from_ref[20];
249250
unsigned char *this_result;
250251

251252
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);
253255
if (r) {
254256
if (!refs_found++)
255257
*ref = xstrdup(r);
@@ -272,7 +274,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
272274
char path[PATH_MAX];
273275
const char *ref, *it;
274276

275-
strcpy(path, mkpath(*p, len, str));
277+
mksnpath(path, sizeof(path), *p, len, str);
276278
ref = resolve_ref(path, hash, 1, NULL);
277279
if (!ref)
278280
continue;

0 commit comments

Comments
 (0)