summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2017-04-26 21:29:36 +0200
committerJunio C Hamano <gitster@pobox.com>2017-04-27 13:07:40 +0900
commit1e65a982da0e9dd4eac440e82392a8b7c72b3def (patch)
treecf0140e50c30905f3aba1ded712b66cb75afc4d6 /date.c
parentdddbad728c93280fe54ef86699b6d70e2aab44d1 (diff)
downloadgit-1e65a982da0e9dd4eac440e82392a8b7c72b3def.tar.gz
date.c: abort if the system time cannot handle one of our timestamps
We are about to switch to a new data type for time stamps that is definitely not smaller or equal, but larger or equal to time_t. So before using the system functions to process or format timestamps, let's make extra certain that they can handle what we feed them. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'date.c')
-rw-r--r--date.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/date.c b/date.c
index 92ab31aa44..63fa99685e 100644
--- a/date.c
+++ b/date.c
@@ -46,7 +46,17 @@ static time_t gm_time_t(timestamp_t time, int tz)
minutes = tz < 0 ? -tz : tz;
minutes = (minutes / 100)*60 + (minutes % 100);
minutes = tz < 0 ? -minutes : minutes;
- return time + minutes * 60;
+
+ if (minutes > 0) {
+ if (unsigned_add_overflows(time, minutes * 60))
+ die("Timestamp+tz too large: %"PRItime" +%04d",
+ time, tz);
+ } else if (time < -minutes * 60)
+ die("Timestamp before Unix epoch: %"PRItime" %04d", time, tz);
+ time += minutes * 60;
+ if (date_overflows(time))
+ die("Timestamp too large for this system: %"PRItime, time);
+ return (time_t)time;
}
/*
@@ -70,7 +80,10 @@ static int local_tzoffset(timestamp_t time)
struct tm tm;
int offset, eastwest;
- t = time;
+ if (date_overflows(time))
+ die("Timestamp too large for this system: %"PRItime, time);
+
+ t = (time_t)time;
localtime_r(&t, &tm);
t_local = tm_to_time_t(&tm);