diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-01-16 11:50:12 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-01-16 11:53:43 +0100 |
commit | bac794f6071152977f1b6f8478282c440c8e0e19 (patch) | |
tree | dfadf64e18b63f85316eea94e49867e29c6a51f0 /src/basic/parse-util.c | |
parent | b5ffbc55791612749ef36925a56e7d2d6fe5227b (diff) | |
download | systemd-bac794f6071152977f1b6f8478282c440c8e0e19.tar.gz systemd-bac794f6071152977f1b6f8478282c440c8e0e19.tar.bz2 systemd-bac794f6071152977f1b6f8478282c440c8e0e19.zip |
parse-util: detect overflows in parse_percent_unbounded()
We shouldn't accept percentages beyon INT32_MAX and consider them
valid.
Diffstat (limited to 'src/basic/parse-util.c')
-rw-r--r-- | src/basic/parse-util.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index 14687b16a0..2c22753dea 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -592,19 +592,20 @@ int parse_fractional_part_u(const char **p, size_t digits, unsigned *res) { int parse_percent_unbounded(const char *p) { const char *pc, *n; - unsigned v; - int r; + int r, v; pc = endswith(p, "%"); if (!pc) return -EINVAL; n = strndupa(p, pc - p); - r = safe_atou(n, &v); + r = safe_atoi(n, &v); if (r < 0) return r; + if (v < 0) + return -ERANGE; - return (int) v; + return v; } int parse_percent(const char *p) { |