@matheusbsbs / matheus-bagliano / commits / 9ba0f0334d
Fork 0

parse_date: fix signedness in timezone calculation

When no timezone is specified, we deduce the offset by subtracting the result of mktime from our calculated timestamp. However, our timestamp is stored as an unsigned integer, meaning we perform the subtraction as unsigned. For a negative offset, this means we wrap to a very high number, and our numeric timezone is in the millions of hours. You can see this bug by doing: $ TZ=EST \ GIT_AUTHOR_DATE='2010-06-01 10:00' \ git commit -a -m foo $ git cat-file -p HEAD | grep author author Jeff King <peff@peff.net> 1275404416 +119304128 Instead, we should perform this subtraction as a time_t, the same type that mktime returns. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 4, 2010 at 07:00 UTC 9ba0f0334dd505f78e0374bbe857c5e202f5a778
2 files changed +2 -1
date.c
+1 -1
@@ -635,7 +635,7 @@ int parse_date_toffset(const char *date, unsigned long *timestamp, int *offset)
635 /* mktime uses local timezone */
636 *timestamp = tm_to_time_t(&tm);
637 if (*offset == -1)
638 - *offset = (*timestamp - mktime(&tm)) / 60;
638 + *offset = ((time_t)*timestamp - mktime(&tm)) / 60;
639
640 if (*timestamp == -1)
641 return -1;
t/t0006-date.sh
+1
@@ -39,6 +39,7 @@ check_parse 2008-02 bad
39 check_parse 2008-02-14 bad
40 check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 +0000'
41 check_parse '2008-02-14 20:30:45 -0500' '2008-02-14 20:30:45 -0500'
42 +check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 -0500' EST
43
44 check_approxidate() {
45 echo "$1 -> $2 +0000" >expect