Skip to content

Commit 861f00e

Browse files
peffgitster
authored andcommitted
fix reflog approxidate parsing bug
In get_sha1_basic, we parse a string like HEAD@{10 seconds ago}:path/to/file into its constituent ref, reflog date, and path components. We never actually munge the string itself, but instead keep offsets into the string with their associated lengths. When we call approxidate on the contents inside braces, however, we pass just a string without a length. This means that approxidate could sometimes look past the closing brace and (erroneously) interpret the rest of the string as part of the date. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 362b0dd commit 861f00e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

sha1_name.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,11 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
352352
}
353353
if (0 <= nth)
354354
at_time = 0;
355-
else
356-
at_time = approxidate(str + at + 2);
355+
else {
356+
char *tmp = xstrndup(str + at + 2, reflog_len);
357+
at_time = approxidate(tmp);
358+
free(tmp);
359+
}
357360
if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
358361
&co_time, &co_tz, &co_cnt)) {
359362
if (at_time)

0 commit comments

Comments
 (0)