Skip to content

Commit f6e6362

Browse files
committed
parse_date_basic(): let the system handle DST conversion
The function parses the input to compute the broken-down time in "struct tm", and the GMT timezone offset. If the timezone offset does not exist in the input, the broken-down time is turned into the number of seconds since epoch both in the current timezone and in GMT and the offset is computed as their difference. However, we forgot to make sure tm.tm_isdst is set to -1 (i.e. let the system figure out if DST is in effect in the current timezone when turning the broken-down time to the number of seconds since epoch); it is done so at the beginning of the function, but a call to match_digit() in the function can lead to a call to gmtime_r() to clobber the field. Reported-by: Linus Torvalds <[email protected]> Diagnosed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7fcec48 commit f6e6362

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

date.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,13 +694,17 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
694694
date += match;
695695
}
696696

697-
/* mktime uses local timezone */
697+
/* do not use mktime(), which uses local timezone, here */
698698
*timestamp = tm_to_time_t(&tm);
699699
if (*timestamp == -1)
700700
return -1;
701701

702702
if (*offset == -1) {
703-
time_t temp_time = mktime(&tm);
703+
time_t temp_time;
704+
705+
/* gmtime_r() in match_digit() may have clobbered it */
706+
tm.tm_isdst = -1;
707+
temp_time = mktime(&tm);
704708
if ((time_t)*timestamp > temp_time) {
705709
*offset = ((time_t)*timestamp - temp_time) / 60;
706710
} else {

0 commit comments

Comments
 (0)