diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-03 16:00:59 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-03 20:39:19 +0900 |
commit | 9f819781caee1b9a0bfe3a3211455a940a06f1ae (patch) | |
tree | 32665ccc7419f7b1073f0d6d965cdbf16c79dcbd /src | |
parent | 87e0fd575e8b5a747d25b0bd4cf5a7061c6f6ece (diff) | |
download | systemd-9f819781caee1b9a0bfe3a3211455a940a06f1ae.tar.gz |
time-util: refuse non-zero gmtoff with non-UTC timezone
Also this moves the range check for gmtoff to parse_timestamp_impl(), to
address the post-merge comment:
https://github.com/systemd/systemd/pull/26409#discussion_r1118650190
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/time-util.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index a76bb6bc57..26fd1bae65 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -679,6 +679,15 @@ static int parse_timestamp_impl( with_tz = true; } + if (utc) { + /* glibc accepts gmtoff more than 24 hours, but we refuse it. */ + if ((usec_t) labs(gmtoff) * USEC_PER_SEC > USEC_PER_DAY) + return -EINVAL; + } else { + if (gmtoff != 0) + return -EINVAL; + } + if (t[0] == '@' && !with_tz) return parse_sec(t + 1, ret); @@ -948,13 +957,8 @@ int parse_timestamp(const char *t, usec_t *ret) { * UTC and shift the result. Note, this must be earlier than the timezone check with tzname[], as * tzname[] may be in the same format. */ k = strptime(tz, "%z", &tm); - if (k && *k == '\0') { - /* glibc accepts gmtoff more than 24 hours, but we refuse it. */ - if ((usec_t) labs(tm.tm_gmtoff) > USEC_PER_DAY / USEC_PER_SEC) - return -EINVAL; - + if (k && *k == '\0') return parse_timestamp_impl(t, tz_offset, /* utc = */ true, /* isdst = */ -1, /* gmtoff = */ tm.tm_gmtoff, ret); - } /* If the last word is not a timezone file (e.g. Asia/Tokyo), then let's check if it matches * tzname[] of the local timezone, e.g. JST or CEST. */ |