chiark / gitweb /
time-util: make parse_timestamp() set 0 if the input is very old date (#6297)
[elogind.git] / src / basic / time-util.c
index d8997666e5e7dfd4c097c2de5268a8f7d91b17f9..397637f53b561e757ec3076fde92f6e29b2a549c 100644 (file)
@@ -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;