Merge branch 'jk/commit-dates-parsing-fix'

Tighten codepaths that parse timestamps in commit objects.

* 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
This commit is contained in:
Junio C Hamano
2014-03-14 14:25:44 -07:00
6 changed files with 96 additions and 11 deletions

23
date.c
View File

@ -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);
}