This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
- From: Florian Weimer <fweimer at redhat dot com>
- To: Mingli Yu <Mingli dot Yu at windriver dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Wed, 19 Sep 2018 22:51:54 +0200
- Subject: [PATCH] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
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
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;