This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
- From: "Yu, Mingli" <mingli dot yu at windriver dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: <libc-alpha at sourceware dot org>
- Date: Thu, 20 Sep 2018 10:06:05 +0800
- Subject: Re: [PATCH] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
- References: <87zhwdjjmd.fsf@oldenburg.str.redhat.com>
On 2018年09月20日 04:51, Florian Weimer wrote:
Compared to the version posted on Bugzilla, I added a check on ret. If
ret == 0 and hp == NULL, herr and errno are not necessarily valid.
Okay for master?
Thanks Florian for your respond! I'm fine with your update for the patch.
Thanks,
Mingli
Thanks,
Florian
Commit message:
Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
A NULL value can happen with certain gethostbyname_r failures.
ChangeLog entry:
2018-09-19 Mingli Yu <Mingli.Yu@windriver.com>
* sysdeps/unix/sysv/linux/gethostid.c (gethostid): Check for NULL
value from gethostbyname_r.
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;