]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nss: Fix UB on test-netdb
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 23 Apr 2025 19:40:57 +0000 (16:40 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 8 May 2025 12:25:44 +0000 (09:25 -0300)
The gethostname is defined as not accepting NULL arguments, so
use a minimal size for initial call.

nss/test-netdb.c

index 3911c3c42aa83eb83069bc757cc16d11a6bcfb7b..b7125cfed1d2d4f86ae1dcf3f155e93fe4a0f7fd 100644 (file)
@@ -178,6 +178,9 @@ test_hosts (void)
   hptr1 = gethostbyname2 ("localhost", AF_INET);
   output_hostent ("gethostbyname2 (\"localhost\", AF_INET)", hptr1);
 
+  name = xmalloc (2);
+  namelen += 2;
+
   while (gethostname (name, namelen) < 0 && errno == ENAMETOOLONG)
     {
       namelen += 2;            /* tiny increments to test a lot */