]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
time-util: when converting to time_t do something useful in 2038
authorLennart Poettering <lennart@poettering.net>
Thu, 2 Feb 2017 17:33:36 +0000 (18:33 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 2 Feb 2017 19:12:31 +0000 (20:12 +0100)
On systems where time_t is 32bit we should invalidate the
timeval/timespec instead of proceeding with a potentially overflown
value.

src/basic/time-util.c

index eefbf9092329fbf594685abebdcd694e28cbff90..4070ee182efbe4dd419989a465f84efe65c26674 100644 (file)
@@ -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 {