mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
util: check overflow in parse_nsec()
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user