Subject: Re: [PATCH iproute2-next v2] dcb: Fix compilation warning about reallocarray

From: Petr Machata <[email-masked]>
Date: Mon, 22 Feb 2021 13:30:02 +0100

Roi Dayan <[email-masked]> writes:

> --- a/dcb/dcb_app.c
> +++ b/dcb/dcb_app.c
> @@ -65,8 +65,7 @@ static void dcb_app_table_fini(struct dcb_app_table *tab)
>  
>  static int dcb_app_table_push(struct dcb_app_table *tab, struct dcb_app *app)
>  {
> -	struct dcb_app *apps = reallocarray(tab->apps, tab->n_apps + 1,
> -					    sizeof(*tab->apps));
> +	struct dcb_app *apps = realloc(tab->apps, (tab->n_apps + 1) * sizeof(*tab->apps));

reallocarray() checks that count*size does not overflow. But the whole
APP table needs to fit into one attribute, which limits the size to some
64K, so from UAPI direction this will never overflow. From the
command-line direction, size of 'struct app' is 4 bytes, so to overflow
you'd need to stuff in 1G APP entries. I think we don't need to worry
about that.

So this looks good.

Reviewed-by: Petr Machata <[email-masked]>