diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-07-20 13:22:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-20 13:22:01 +0200 |
commit | 9638adaf21e8426ebed18a5d74d3163f1087b0e5 (patch) | |
tree | b96dbdc7e3d4b47dfefcc165de27e1abf2942ec2 /src/basic | |
parent | efe6112dc5f73a9c8371ea127f497f1cfdcbb7be (diff) | |
parent | 279f52a1d358efbdfa106dbef301a76a8155b666 (diff) | |
download | systemd-9638adaf21e8426ebed18a5d74d3163f1087b0e5.tar.gz systemd-9638adaf21e8426ebed18a5d74d3163f1087b0e5.tar.bz2 systemd-9638adaf21e8426ebed18a5d74d3163f1087b0e5.zip |
Merge pull request #9614 from poettering/negative-sec
parse-util: make sure "-0.-0s" is not considered a valid time specifiā¦
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/time-util.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index fe201c398d..81d3f3f38f 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ +#include <ctype.h> #include <errno.h> #include <limits.h> #include <stdlib.h> @@ -996,10 +997,10 @@ int parse_time(const char *t, usec_t *usec, usec_t default_unit) { } for (;;) { + usec_t multiplier = default_unit, k; long long l, z = 0; - char *e; unsigned n = 0; - usec_t multiplier = default_unit, k; + char *e; p += strspn(p, WHITESPACE); @@ -1010,6 +1011,9 @@ int parse_time(const char *t, usec_t *usec, usec_t default_unit) { break; } + if (*p == '-') /* Don't allow "-0" */ + return -ERANGE; + errno = 0; l = strtoll(p, &e, 10); if (errno > 0) @@ -1020,14 +1024,16 @@ int parse_time(const char *t, usec_t *usec, usec_t default_unit) { if (*e == '.') { char *b = e + 1; + /* Don't allow "0.-0", "3.+1" or "3. 1" */ + if (*b == '-' || *b == '+' || isspace(*b)) + return -EINVAL; + errno = 0; z = strtoll(b, &e, 10); if (errno > 0) return -errno; - if (z < 0) return -ERANGE; - if (e == b) return -EINVAL; @@ -1144,26 +1150,28 @@ int parse_nsec(const char *t, nsec_t *nsec) { break; } + if (*p == '-') + return -ERANGE; + errno = 0; l = strtoll(p, &e, 10); - if (errno > 0) return -errno; - if (l < 0) return -ERANGE; if (*e == '.') { char *b = e + 1; + if (*b == '-' || *b == '+' || isspace(*b)) + return -EINVAL; + errno = 0; z = strtoll(b, &e, 10); if (errno > 0) return -errno; - if (z < 0) return -ERANGE; - if (e == b) return -EINVAL; |