Skip to content

Commit

Permalink
fix reflog approxidate parsing bug
Browse files Browse the repository at this point in the history
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Apr 30, 2008
1 parent 362b0dd commit 861f00e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sha1_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,11 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
}
if (0 <= nth)
at_time = 0;
else
at_time = approxidate(str + at + 2);
else {
char *tmp = xstrndup(str + at + 2, reflog_len);
at_time = approxidate(tmp);
free(tmp);
}
if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
&co_time, &co_tz, &co_cnt)) {
if (at_time)
Expand Down

0 comments on commit 861f00e

Please sign in to comment.