{"thread":{"id":"13324","subject":"[PATCH] fix reflog approxidate parsing bug","startedAt":"2008-04-30T04:13:58Z","lastAt":"2008-04-30T04:13:58Z","messageCount":1,"participants":["Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"75628","messageId":"20080430041358.GA30494@sigill.intra.peff.net","threadId":"13324","inReplyTo":null,"subject":"[PATCH] fix reflog approxidate parsing bug","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-04-30T04:13:58Z","receivedAt":"2008-04-30T04:13:58Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"In get_sha1_basic, we parse a string like\n\n  HEAD@{10 seconds ago}:path/to/file\n\ninto its constituent ref, reflog date, and path components.\nWe never actually munge the string itself, but instead keep\noffsets into the string with their associated lengths.\n\nWhen we call approxidate on the contents inside braces,\nhowever, we pass just a string without a length. This means\nthat approxidate could sometimes look past the closing brace\nand (erroneously) interpret the rest of the string as part\nof the date.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nSorry, I don't have a concise way of writing a test-case. Geoff's\nexample shows the bug when parsing:\n\n  HEAD{10 seconds ago}:data/node/node.newds1\n\nbut it works OK with:\n\n  HEAD{10 seconds ago}:data/node\n\nI didn't track down the exact conditions that cause approxidate to not\nlike the string, since it seems wrong to be sending it a non-terminated\nstring anyway.\n\n sha1_name.c |    7 +++++--\n 1 files changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 491d2e7..b0b2167 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -351,8 +351,11 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)\n \t\t}\n \t\tif (0 <= nth)\n \t\t\tat_time = 0;\n-\t\telse\n-\t\t\tat_time = approxidate(str + at + 2);\n+\t\telse {\n+\t\t\tchar *tmp = xstrndup(str + at + 2, reflog_len);\n+\t\t\tat_time = approxidate(tmp);\n+\t\t\tfree(tmp);\n+\t\t}\n \t\tif (read_ref_at(real_ref, at_time, nth, sha1, NULL,\n \t\t\t\t&co_time, &co_tz, &co_cnt)) {\n \t\t\tif (at_time)\n-- \n1.5.5.1.178.gc1eb9.dirty\n"}]}