diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-04-12 10:51:51 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-05-16 09:04:10 +0200 |
commit | 0e77bf296648c5db92c269c678d27f6846de4e9f (patch) | |
tree | 850b14114f9b1c99ca04062fbfc7394d7da2a35d | |
parent | b45e162eca2c6e913318c4552643aae2a973ae3a (diff) | |
download | firewall3-0e77bf296648c5db92c269c678d27f6846de4e9f.tar.gz |
options: treat time strings as UTC times
When parsing user supplied time strings, calculate an UTC time instant by
substracting the current zone offset from the result of mktime(3), then use
gmtime_r(3) to turn the time_t value back into a sanitized time structure.
This ensures that user supplied dates are not interpreted as local time.
Fixes FS#1483.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | options.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -641,6 +641,7 @@ fw3_parse_date(void *ptr, const char *val, bool is_list) { unsigned int year = 1970, mon = 1, day = 1, hour = 0, min = 0, sec = 0; struct tm tm = { 0 }; + time_t ts; char *p; year = strtoul(val, &p, 10); @@ -685,9 +686,11 @@ ret: tm.tm_min = min; tm.tm_sec = sec; - if (mktime(&tm) >= 0) + ts = mktime(&tm) - timezone; + + if (ts >= 0) { - *((struct tm *)ptr) = tm; + gmtime_r(&ts, (struct tm *)ptr); return true; } |