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

Adhemerval Zanella via Glibc-cvs <[email protected]>
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c1e0787b56f9ebd51d642c21b785143984f3e1f1

commit c1e0787b56f9ebd51d642c21b785143984f3e1f1
Author: Marcus Poller <[email protected]>
Date:   Mon Jul 6 10:37:32 2026 +0200

    nss: Use reallocarray to prevent integer overflow in getaddrinfo (bug 33977)
    
    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.
    
    Reviewed-by: Adhemerval Zanella <[email protected]>

Diff:
---
 nss/getaddrinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nss/getaddrinfo.c b/nss/getaddrinfo.c
index 4f6ac3358a..45b7f728a1 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 = __libc_reallocarray (res->at, old + count, sizeof (*array));
 
   if (array == NULL)
     return false;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.