Code

fix reflog approxidate parsing bug
authorJeff King <peff@peff.net>
Wed, 30 Apr 2008 04:13:58 +0000 (00:13 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 30 Apr 2008 05:22:19 +0000 (22:22 -0700)
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>
sha1_name.c

index 6c9c1c75adefe2d5e38212b75302368293c9137b..6298c37ae3a9b516ff75c122abf2181827f32bce 100644 (file)
@@ -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)