summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-11-07 01:12:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-11-07 02:04:06 (GMT)
commitaa097b88e91bd748c4508b042e618e8292e15ad5 (patch)
tree56ebd7c6992dc9e88b6483cf4bcd9a148c0e0a55 /date.c
parent8a2c174677e62fe778f5616bf67097cad3a5636e (diff)
downloadgit-aa097b88e91bd748c4508b042e618e8292e15ad5.zip
git-aa097b88e91bd748c4508b042e618e8292e15ad5.tar.gz
git-aa097b88e91bd748c4508b042e618e8292e15ad5.tar.bz2
approxidate: fix NULL dereference in date_time()
When we see a time like "noon", we pass "12" to our date_time() helper, which sets the hour to 12pm. If the current time is before noon, then we wrap around to yesterday using date_yesterday(). But unlike the normal calls to date_yesterday() from approxidate_alpha(), we pass a NULL "num" parameter. Since c27cc94fad (approxidate: handle pending number for "specials", 2018-11-02), that causes a segfault. One way to fix this is by checking for NULL. But arguably date_time() is abusing our helper by passing NULL in the first place (and this is the only case where one of these "special" parsers is used this way). So instead, let's have it just do the 1-day subtraction itself. It's still just a one-liner due to our update_tm() helper. Note that the test added here is a little funny, as we say "10am noon", which makes the "10am" seem pointless. But this bug can only be triggered when it the currently-parsed hour is before the special time. The latest special time is "tea" at 1700, but t0006 uses a hard-coded TEST_DATE_NOW of 1900. We could reset TEST_DATE_NOW, but that may lead to confusion in other tests. Just saying "10am noon" makes this test self-contained. Reported-by: Carlo Arenas <carenas@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'date.c')
-rw-r--r--date.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/date.c b/date.c
index 7adce32..9bc15df 100644
--- a/date.c
+++ b/date.c
@@ -929,7 +929,7 @@ static void date_yesterday(struct tm *tm, struct tm *now, int *num)
static void date_time(struct tm *tm, struct tm *now, int hour)
{
if (tm->tm_hour < hour)
- date_yesterday(tm, now, NULL);
+ update_tm(tm, now, 24*60*60);
tm->tm_hour = hour;
tm->tm_min = 0;
tm->tm_sec = 0;