public inbox for libc-stable@sourceware.org
 help / color / mirror / Atom feed
From: fweimer@redhat.com (Florian Weimer)
To: libc-stable@sourceware.org
Subject: [2.28 COMMITTED] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
Date: Mon, 01 Jan 2018 00:00:00 -0000	[thread overview]
Message-ID: <20180920154651.D663E441981D1@oldenburg.str.redhat.com> (raw)

From: Mingli Yu <Mingli.Yu@windriver.com>

A NULL value can happen with certain gethostbyname_r failures.

(cherry picked from commit 1214ba06e6771acb953a190091b0f6055c64fd25)

2018-09-20  Mingli Yu  <Mingli.Yu@windriver.com>

	* sysdeps/unix/sysv/linux/gethostid.c (gethostid): Check for NULL
	value from gethostbyname_r.

diff --git a/NEWS b/NEWS
index 2855ffde58..502e0c19f5 100644
--- 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
diff --git a/sysdeps/unix/sysv/linux/gethostid.c b/sysdeps/unix/sysv/linux/gethostid.c
index 2e20f034dc..ee0190e7f9 100644
--- a/sysdeps/unix/sysv/linux/gethostid.c
+++ b/sysdeps/unix/sysv/linux/gethostid.c
@@ -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;

                 reply	other threads:[~2018-09-20 15:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180920154651.D663E441981D1@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-stable@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).