diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-10-23 22:24:16 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-10-23 22:24:16 +0900 |
commit | f6a178e91dd5fccf43f659eca887788fd5dcdccf (patch) | |
tree | 3483a09b108aee165660249a244abd8d6e6a098f /src/basic/time-util.c | |
parent | 8079c90333422bbc008b68a9b7cefbdb8a15a4e9 (diff) | |
download | systemd-f6a178e91dd5fccf43f659eca887788fd5dcdccf.tar.gz |
util: check overflow in parse_nsec()
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r-- | src/basic/time-util.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index e24eef4082..4d297394e2 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -1194,12 +1194,22 @@ int parse_nsec(const char *t, nsec_t *nsec) { for (i = 0; i < ELEMENTSOF(table); i++) if (startswith(e, table[i].suffix)) { - nsec_t k = (nsec_t) z * table[i].nsec; + nsec_t k; + + k = ((nsec_t) -1) / table[i].nsec; + if ((nsec_t) l + 1 >= k || (nsec_t) z >= k) + return -ERANGE; + + k = (nsec_t) z * table[i].nsec; for (; n > 0; n--) k /= 10; - r += (nsec_t) l * table[i].nsec + k; + k += (nsec_t) l * table[i].nsec; + if (k >= ((nsec_t) -1) - r) + return -ERANGE; + + r += k; p = e + strlen(table[i].suffix); something = true; |