summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-03-14 21:25:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-03-14 21:25:44 (GMT)
commit3c83b080e4dce42d0f48d28b03691ae1ac0dcde3 (patch)
tree0f8ab0d53aff78a10ea43439c20c02500c733388 /date.c
parentb37f81b7b676fe7ede3fa171535593337a8911c8 (diff)
parent3f419d45ef0dfc33dc301d9ae4737043c091291a (diff)
downloadgit-3c83b080e4dce42d0f48d28b03691ae1ac0dcde3.zip
git-3c83b080e4dce42d0f48d28b03691ae1ac0dcde3.tar.gz
git-3c83b080e4dce42d0f48d28b03691ae1ac0dcde3.tar.bz2
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 83b4166..e1a2cee 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);
+}