2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +00:00

util: Check ranges on string to int/long conversion.

It's required to check ranges to avoid integer overflow because
underlying strtoll() will check only for LLONG_MIN/MAX.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jan Scheurich <jan.scheurich@ericsson.com>
This commit is contained in:
Ilya Maximets
2017-11-29 13:50:43 +03:00
committed by Ben Pfaff
parent 7b398b07cd
commit 65dca9eb09

View File

@@ -700,8 +700,13 @@ str_to_int(const char *s, int base, int *i)
{
long long ll;
bool ok = str_to_llong(s, base, &ll);
if (!ok || ll < INT_MIN || ll > INT_MAX) {
*i = 0;
return false;
}
*i = ll;
return ok;
return true;
}
bool
@@ -709,8 +714,13 @@ str_to_long(const char *s, int base, long *li)
{
long long ll;
bool ok = str_to_llong(s, base, &ll);
if (!ok || ll < LONG_MIN || ll > LONG_MAX) {
*li = 0;
return false;
}
*li = ll;
return ok;
return true;
}
bool