summaryrefslogtreecommitdiffstats
path: root/src/basic/time-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-10-23 15:23:34 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-10-23 15:23:34 +0200
commit8079c90333422bbc008b68a9b7cefbdb8a15a4e9 (patch)
tree5d96cca0f1f4d2cce796caed4c1f80ea64ddc0cb /src/basic/time-util.c
parentanalyze: Add "timespan" command to dump time span in usec (diff)
downloadsystemd-8079c90333422bbc008b68a9b7cefbdb8a15a4e9.tar.xz
systemd-8079c90333422bbc008b68a9b7cefbdb8a15a4e9.zip
util: check overflow in parse_time()
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r--src/basic/time-util.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index 9115c3bf27..e24eef4082 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -1048,12 +1048,21 @@ int parse_time(const char *t, usec_t *usec, usec_t default_unit) {
something = true;
+
+ k = ((usec_t) -1) / multiplier;
+ if ((usec_t) l + 1 >= k || (usec_t) z >= k)
+ return -ERANGE;
+
k = (usec_t) z * multiplier;
for (; n > 0; n--)
k /= 10;
- r += (usec_t) l * multiplier + k;
+ k += (usec_t) l * multiplier;
+ if (k >= ((usec_t) -1) - r)
+ return -ERANGE;
+
+ r += k;
}
*usec = r;