Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 2b15846

Browse files
peffgitster
authored andcommitted
log: do not segfault on gmtime errors
Many code paths assume that show_date and show_ident_date cannot return NULL. For the most part, we handle missing or corrupt timestamps by showing the epoch time t=0. However, we might still return NULL if gmtime rejects the time_t we feed it, resulting in a segfault. Let's catch this case and just format t=0. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1dca155 commit 2b15846

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

date.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
184184
tz = local_tzoffset(time);
185185

186186
tm = time_to_tm(time, tz);
187-
if (!tm)
188-
return NULL;
187+
if (!tm) {
188+
tm = time_to_tm(0, 0);
189+
tz = 0;
190+
}
189191

190192
strbuf_reset(&timebuf);
191193
if (mode == DATE_SHORT)

t/t4212-log-corrupt.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,12 @@ test_expect_success 'date parser recognizes time_t overflow' '
7676
test_cmp expect actual
7777
'
7878

79+
# date is within 2^63-1, but enough to choke glibc's gmtime
80+
test_expect_success 'absurdly far-in-future dates produce sentinel' '
81+
commit=$(munge_author_date HEAD 999999999999999999) &&
82+
echo "Thu Jan 1 00:00:00 1970 +0000" >expect &&
83+
git log -1 --format=%ad $commit >actual &&
84+
test_cmp expect actual
85+
'
86+
7987
test_done

0 commit comments

Comments
 (0)