summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/time-util.c24
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;