]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
authorMingli Yu <Mingli.Yu@windriver.com>
Thu, 20 Sep 2018 10:41:13 +0000 (12:41 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 20 Sep 2018 10:41:13 +0000 (12:41 +0200)
A NULL value can happen with certain gethostbyname_r failures.

(cherry picked from commit 1214ba06e6771acb953a190091b0f6055c64fd25)

ChangeLog
NEWS
sysdeps/unix/sysv/linux/gethostid.c

index d9e7e6f1d8d1dc326c3c3468af8530b92d3d9589..fc1ea1e418a5cb26135e8851ad306d63641e1b88 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-09-20  Mingli Yu  <Mingli.Yu@windriver.com>
+
+       * sysdeps/unix/sysv/linux/gethostid.c (gethostid): Check for NULL
+       value from gethostbyname_r.
+
 2018-09-06  Stefan Liebler  <stli@linux.ibm.com>
 
        * sysdeps/unix/sysv/linux/spawni.c (maybe_script_execute):
diff --git a/NEWS b/NEWS
index 2855ffde58452fd6ec4ede082d8c759e003f86d3..502e0c19f5822fb6425d03431fb11808b03393a9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ The following bugs are resolved with this release:
   [23521] nss_files aliases database file stream leak
   [23538] pthread_cond_broadcast: Fix waiters-after-spinning case
   [23578] regex: Fix memory overread in re_compile_pattern
+  [23679] gethostid: Missing NULL check for gethostbyname_r result
 
 \f
 Version 2.28
index 2e20f034dc134cc7f6cd927a920880bce7efcd29..ee0190e7f945db1f25fcb6546100ee9e97adb4de 100644 (file)
@@ -102,12 +102,12 @@ gethostid (void)
     {
       int ret = __gethostbyname_r (hostname, &hostbuf,
                                   tmpbuf.data, tmpbuf.length, &hp, &herr);
-      if (ret == 0)
+      if (ret == 0 && hp != NULL)
        break;
       else
        {
          /* Enlarge the buffer on ERANGE.  */
-         if (herr == NETDB_INTERNAL && errno == ERANGE)
+         if (ret != 0 && herr == NETDB_INTERNAL && errno == ERANGE)
            {
              if (!scratch_buffer_grow (&tmpbuf))
                return 0;