[PATCH v3] nss: Use reallocarray to prevent integer overflow in getaddrinfo (bug 33977)

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Thu Jun 25 13:22:23 GMT 2026



On 24/06/26 13:00, Marcus Poller wrote:
> replacing realloc by reallocarray introduces a basic overflow check.
> (old + count) might still overflow, but since the NSS backend is trusted,
> we do not consider this to be a valid case.
> ---
> v1: https://inbox.sourceware.org/libc-alpha/77a01db3-5619-48b8-9682-85f11cc472bc@crystaldown.de/
> v2: iterated on Arjuns and Andreas review comments
> v3: re-submission to support existing tooling

Unfortunately this patch has triggered some regressions [1]. But it should be
to fix, just use __libc_reallocarray instead of reallocarray.

[1] https://www.delorie.com/trybots/32bit/62685/

> ---
>  nss/getaddrinfo.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/nss/getaddrinfo.c b/nss/getaddrinfo.c
> index 4f6ac3358a..b6ac0b2dcc 100644
> --- a/nss/getaddrinfo.c
> +++ b/nss/getaddrinfo.c
> @@ -234,7 +234,7 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, int family,
>        array = array->next;
>      }
>  
> -  array = realloc (res->at, (old + count) * sizeof (*array));
> +  array = reallocarray (res->at, old + count, sizeof (*array));
>  
>    if (array == NULL)
>      return false;



More information about the Libc-alpha mailing list