diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-02-02 18:33:36 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-02-02 20:12:31 +0100 |
commit | f977849c244b789c3530a4da8e00f2ad98c79f1f (patch) | |
tree | 372aa2e4b85f7efc0ab4cbb82b56ea8ba33cf469 /src/basic | |
parent | 1bb4b028a380d74cff6399ea1d8ffcf1b2f122bc (diff) |
time-util: when converting to time_t do something useful in 2038
On systems where time_t is 32bit we should invalidate the
timeval/timespec instead of proceeding with a potentially overflown
value.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/time-util.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index eefbf90923..4070ee182e 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -211,7 +211,8 @@ nsec_t timespec_load_nsec(const struct timespec *ts) { struct timespec *timespec_store(struct timespec *ts, usec_t u) { assert(ts); - if (u == USEC_INFINITY) { + if (u == USEC_INFINITY || + u / USEC_INFINITY >= TIME_T_MAX) { ts->tv_sec = (time_t) -1; ts->tv_nsec = (long) -1; return ts; @@ -240,7 +241,8 @@ 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; } else { |