50f89d
commit e7d22db29cfdd2f1fb97a70a76fa53d151569945
50f89d
Author: Mingli Yu <Mingli.Yu@windriver.com>
50f89d
Date:   Thu Sep 20 12:41:13 2018 +0200
50f89d
50f89d
    Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
50f89d
    
50f89d
    A NULL value can happen with certain gethostbyname_r failures.
50f89d
    
50f89d
    (cherry picked from commit 1214ba06e6771acb953a190091b0f6055c64fd25)
50f89d
50f89d
diff --git a/sysdeps/unix/sysv/linux/gethostid.c b/sysdeps/unix/sysv/linux/gethostid.c
50f89d
index 2e20f034dc134cc7..ee0190e7f945db1f 100644
50f89d
--- a/sysdeps/unix/sysv/linux/gethostid.c
50f89d
+++ b/sysdeps/unix/sysv/linux/gethostid.c
50f89d
@@ -102,12 +102,12 @@ gethostid (void)
50f89d
     {
50f89d
       int ret = __gethostbyname_r (hostname, &hostbuf,
50f89d
 				   tmpbuf.data, tmpbuf.length, &hp, &herr;;
50f89d
-      if (ret == 0)
50f89d
+      if (ret == 0 && hp != NULL)
50f89d
 	break;
50f89d
       else
50f89d
 	{
50f89d
 	  /* Enlarge the buffer on ERANGE.  */
50f89d
-	  if (herr == NETDB_INTERNAL && errno == ERANGE)
50f89d
+	  if (ret != 0 && herr == NETDB_INTERNAL && errno == ERANGE)
50f89d
 	    {
50f89d
 	      if (!scratch_buffer_grow (&tmpbuf))
50f89d
 		return 0;