From bab748371a104c58058c0eff9f4073b710ce0355 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 20 Jun 2016 17:14:14 -0400 Subject: local_tzoffset: detect errors from tm_to_time_t When we want to know the local timezone offset at a given timestamp, we compute it by asking for localtime() at the given time, and comparing the offset to GMT at that time. However, there's some juggling between time_t and "struct tm" which happens, which involves calling our own tm_to_time_t(). If that function returns an error (e.g., because it only handles dates up to the year 2099), it returns "-1", which we treat as a time_t, and is clearly bogus, leading to bizarre timestamps (that seem to always adjust the time back to (time_t)(uint32_t)-1, in the year 2106). It's not a good idea for local_tzoffset() to simply die here; it would make it hard to run "git log" on a repository with funny timestamps. Instead, let's just treat such cases as "zero offset". Reported-by: Norbert Kiesel Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- date.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'date.c') diff --git a/date.c b/date.c index 7c9f76998a..4c7aa9ba85 100644 --- a/date.c +++ b/date.c @@ -74,6 +74,8 @@ static int local_tzoffset(unsigned long time) localtime_r(&t, &tm); t_local = tm_to_time_t(&tm); + if (t_local == -1) + return 0; /* error; just use +0000 */ if (t_local < t) { eastwest = -1; offset = t - t_local; -- cgit v1.2.3