From: Lennart Poettering Date: Tue, 16 Jan 2018 10:50:12 +0000 (+0100) Subject: parse-util: detect overflows in parse_percent_unbounded() X-Git-Tag: v237~91^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bac794f6071152977f1b6f8478282c440c8e0e19;p=platform%2Fupstream%2Fsystemd.git parse-util: detect overflows in parse_percent_unbounded() We shouldn't accept percentages beyon INT32_MAX and consider them valid. --- diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index 14687b1..2c22753 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) {