chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
ffe6e97
)
parse-util: detect overflows in parse_percent_unbounded()
author
Lennart Poettering
<lennart@poettering.net>
Tue, 16 Jan 2018 10:50:12 +0000
(11:50 +0100)
committer
Sven Eden
<yamakuzure@gmx.net>
Wed, 30 May 2018 05:50:09 +0000
(07:50 +0200)
We shouldn't accept percentages beyon INT32_MAX and consider them
valid.
src/basic/parse-util.c
patch
|
blob
|
history
diff --git
a/src/basic/parse-util.c
b/src/basic/parse-util.c
index 8d97f017c23adfb4ce5648ca469f8f3b2bf808fa..54d1081a0470a5747ae49f3d07d769a6cf636737 100644
(file)
--- a/
src/basic/parse-util.c
+++ b/
src/basic/parse-util.c
@@
-597,19
+597,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_ato
u
(n, &v);
+ r = safe_ato
i
(n, &v);
if (r < 0)
return r;
+ if (v < 0)
+ return -ERANGE;
- return
(int)
v;
+ return v;
}
int parse_percent(const char *p) {