Merge pull request #9614 from poettering/negative-sec

parse-util: make sure "-0.-0s" is not considered a valid time specifi…
This commit is contained in:
Lennart Poettering
2018-07-20 13:22:01 +02:00
committed by GitHub
2 changed files with 41 additions and 9 deletions
+17 -9
View File
@@ -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 (;;) {
long long l, z = 0;
char *e;
unsigned n = 0;
usec_t multiplier = default_unit, k;
long long l, z = 0;
unsigned n = 0;
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;