[ovs-dev] [PATCH 1/3] util: Check ranges on string to int/long conversion.
Jan Scheurich
jan.scheurich at ericsson.com
Wed Nov 29 14:59:25 UTC 2017
Acked-by: Jan Scheurich <jan.scheurich at ericsson.com>
> -----Original Message-----
> From: ovs-dev-bounces at openvswitch.org [mailto:ovs-dev-bounces at openvswitch.org] On Behalf Of Ilya Maximets
> Sent: Wednesday, 29 November, 2017 11:51
> To: ovs-dev at openvswitch.org
> Cc: Ilya Maximets <i.maximets at samsung.com>; Heetae Ahn <heetae82.ahn at samsung.com>
> Subject: [ovs-dev] [PATCH 1/3] 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 at samsung.com>
> ---
> lib/util.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/lib/util.c b/lib/util.c
> index 62f5fa2..ac982d5 100644
> --- a/lib/util.c
> +++ b/lib/util.c
> @@ -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
> --
> 2.7.4
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
More information about the dev
mailing list