diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-03-18 14:04:01 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-03-18 14:04:01 -0700 |
commit | 8aac6c97e81dee53ae7740663128b0296398d6d1 (patch) | |
tree | d6977ae7a154fe5ddb272c5e6475eb9fd4467c05 /date.c | |
parent | Merge branch 'tr/diff-submodule-no-reuse-worktree' into maint (diff) | |
parent | show_ident_date: fix tz range check (diff) | |
download | tgif-8aac6c97e81dee53ae7740663128b0296398d6d1.tar.xz |
Merge branch 'jk/commit-dates-parsing-fix' into maint
Codepaths that parse timestamps in commit objects have been
tightened.
* jk/commit-dates-parsing-fix:
show_ident_date: fix tz range check
log: do not segfault on gmtime errors
log: handle integer overflow in timestamps
date: check date overflow against time_t
fsck: report integer overflow in author timestamps
t4212: test bogus timestamps with git-log
Diffstat (limited to 'date.c')
-rw-r--r-- | date.c | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -184,8 +184,10 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode) tz = local_tzoffset(time); tm = time_to_tm(time, tz); - if (!tm) - return NULL; + if (!tm) { + tm = time_to_tm(0, 0); + tz = 0; + } strbuf_reset(&timebuf); if (mode == DATE_SHORT) @@ -1113,3 +1115,20 @@ unsigned long approxidate_careful(const char *date, int *error_ret) gettimeofday(&tv, NULL); return approxidate_str(date, &tv, error_ret); } + +int date_overflows(unsigned long t) +{ + time_t sys; + + /* If we overflowed our unsigned long, that's bad... */ + if (t == ULONG_MAX) + return 1; + + /* + * ...but we also are going to feed the result to system + * functions that expect time_t, which is often "signed long". + * Make sure that we fit into time_t, as well. + */ + sys = t; + return t != sys || (t < 1) != (sys < 1); +} |