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