summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2014-03-14 14:25:44 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2014-03-14 14:25:44 -0700
commit3c83b080e4dce42d0f48d28b03691ae1ac0dcde3 (patch)
tree0f8ab0d53aff78a10ea43439c20c02500c733388 /date.c
parentMerge branch 'jh/note-trees-record-blobs' (diff)
parentshow_ident_date: fix tz range check (diff)
downloadtgif-3c83b080e4dce42d0f48d28b03691ae1ac0dcde3.tar.xz
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
Diffstat (limited to 'date.c')
-rw-r--r--date.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/date.c b/date.c
index 83b4166344..e1a2cee568 100644
--- a/date.c
+++ b/date.c
@@ -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);
+}