summaryrefslogtreecommitdiff
path: root/src/basic/calendarspec.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-02-02 18:30:29 +0100
committerLennart Poettering <lennart@poettering.net>2017-02-02 20:12:31 +0100
commit1bb4b028a380d74cff6399ea1d8ffcf1b2f122bc (patch)
tree041f20a932fbf9d318cf5484bf5e22e8cddae5bc /src/basic/calendarspec.c
parentc477ff141b875a2a98c90514b6bf23f0436d1f73 (diff)
time-util: refuse formatting/parsing times that we can't store
usec_t is always 64bit, which means it can cover quite a number of years. However, 4 digit year display and glibc limitations around time_t limit what we can actually parse and format. Let's make this explicit, so that we never end up formatting dates we can#t parse and vice versa. Note that this is really just about formatting/parsing. Internal calculations with times outside of the formattable range are not affected.
Diffstat (limited to 'src/basic/calendarspec.c')
-rw-r--r--src/basic/calendarspec.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c
index 35dfb6a3db..3fa1c51ace 100644
--- a/src/basic/calendarspec.c
+++ b/src/basic/calendarspec.c
@@ -1228,6 +1228,9 @@ int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *next)
assert(spec);
assert(next);
+ if (usec > USEC_TIMESTAMP_FORMATTABLE_MAX)
+ return -EINVAL;
+
usec++;
t = (time_t) (usec / USEC_PER_SEC);
assert_se(localtime_or_gmtime_r(&t, &tm, spec->utc));