diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2017-07-12 02:12:48 +0900 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-07-11 19:12:48 +0200 |
commit | 68bdd2d2d3c88dd738c2b9a6fabf518111e204a9 (patch) | |
tree | fe08135c63ce9f6cbf83cf6109275a3dd8b9faa2 /src/basic/time-util.c | |
parent | 634735b56b82bdde3c67193ba7b470bab80fdcbd (diff) | |
download | systemd-68bdd2d2d3c88dd738c2b9a6fabf518111e204a9.tar.gz systemd-68bdd2d2d3c88dd738c2b9a6fabf518111e204a9.tar.bz2 systemd-68bdd2d2d3c88dd738c2b9a6fabf518111e204a9.zip |
time-util: make parse_timestamp() return -EINVAL if the input is very old date (#6327)
This reverts 7635ab8e74ea4a94e81143c3077570a986df375c and makes parse_timestamp()
return -EINVAL if the input is older than 1970-01-01.
Fixes #6290.
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r-- | src/basic/time-util.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 151b44a8d9..68ba86f6a5 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -241,7 +241,7 @@ usec_t timeval_load(const struct timeval *tv) { struct timeval *timeval_store(struct timeval *tv, usec_t u) { assert(tv); - if (u == USEC_INFINITY|| + if (u == USEC_INFINITY || u / USEC_PER_SEC > TIME_T_MAX) { tv->tv_sec = (time_t) -1; tv->tv_usec = (suseconds_t) -1; @@ -847,31 +847,27 @@ parse_usec: from_tm: x = mktime_or_timegm(&tm, utc); - if (x == (time_t) -1) - return -EOVERFLOW; + if (x < 0) + return -EINVAL; if (weekday >= 0 && tm.tm_wday != weekday) return -EINVAL; - if (x < 0) - ret = 0; - else - ret = (usec_t) x * USEC_PER_SEC + x_usec; - + ret = (usec_t) x * USEC_PER_SEC + x_usec; if (ret > USEC_TIMESTAMP_FORMATTABLE_MAX) return -EINVAL; finish: if (ret + plus < ret) /* overflow? */ - return -EOVERFLOW; + return -EINVAL; ret += plus; if (ret > USEC_TIMESTAMP_FORMATTABLE_MAX) return -EINVAL; - if (ret > minus) + if (ret >= minus) ret -= minus; else - ret = 0; + return -EINVAL; *usec = ret; |