From: Yu Watanabe Date: Sat, 8 Jul 2017 19:59:07 +0000 (+0900) Subject: time-util: make parse_timestamp() set 0 if the input is very old date (#6297) X-Git-Tag: chiark/234.4-1+devuan1.1+iwj1~76 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=774663fa082de3fe169d1ae5de8757a92d58a4c5;p=elogind.git time-util: make parse_timestamp() set 0 if the input is very old date (#6297) If the input is older than "1970-01-01 UTC", then `parse_timestamp()` fails and returns -EINVAL. However, if the input is e.g. `-100years`, then the function succeeds and sets `usec = 0`. This commit makes the function also succeed for old dates and set `usec = 0`. Fixes #6290. --- diff --git a/src/basic/time-util.c b/src/basic/time-util.c index d8997666e..397637f53 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -860,19 +860,23 @@ parse_usec: from_tm: x = mktime_or_timegm(&tm, utc); - if (x < 0) - return -EINVAL; + if (x == (time_t) -1) + return -EOVERFLOW; if (weekday >= 0 && tm.tm_wday != weekday) return -EINVAL; - ret = (usec_t) x * USEC_PER_SEC + x_usec; + if (x < 0) + ret = 0; + else + ret = (usec_t) x * USEC_PER_SEC + x_usec; + if (ret > USEC_TIMESTAMP_FORMATTABLE_MAX) return -EINVAL; finish: if (ret + plus < ret) /* overflow? */ - return -EINVAL; + return -EOVERFLOW; ret += plus; if (ret > USEC_TIMESTAMP_FORMATTABLE_MAX) return -EINVAL;