Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]

A NULL value can happen with certain gethostbyname_r failures.

(cherry picked from commit 1214ba06e6)
This commit is contained in:
Mingli Yu 2018-09-20 12:41:13 +02:00 committed by Florian Weimer
parent 1fe2b9ca8a
commit e7d22db29c
3 changed files with 8 additions and 2 deletions

View File

@ -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> 2018-09-06 Stefan Liebler <stli@linux.ibm.com>
* sysdeps/unix/sysv/linux/spawni.c (maybe_script_execute): * sysdeps/unix/sysv/linux/spawni.c (maybe_script_execute):

1
NEWS
View File

@ -13,6 +13,7 @@ The following bugs are resolved with this release:
[23521] nss_files aliases database file stream leak [23521] nss_files aliases database file stream leak
[23538] pthread_cond_broadcast: Fix waiters-after-spinning case [23538] pthread_cond_broadcast: Fix waiters-after-spinning case
[23578] regex: Fix memory overread in re_compile_pattern [23578] regex: Fix memory overread in re_compile_pattern
[23679] gethostid: Missing NULL check for gethostbyname_r result
Version 2.28 Version 2.28

View File

@ -102,12 +102,12 @@ gethostid (void)
{ {
int ret = __gethostbyname_r (hostname, &hostbuf, int ret = __gethostbyname_r (hostname, &hostbuf,
tmpbuf.data, tmpbuf.length, &hp, &herr); tmpbuf.data, tmpbuf.length, &hp, &herr);
if (ret == 0) if (ret == 0 && hp != NULL)
break; break;
else else
{ {
/* Enlarge the buffer on ERANGE. */ /* Enlarge the buffer on ERANGE. */
if (herr == NETDB_INTERNAL && errno == ERANGE) if (ret != 0 && herr == NETDB_INTERNAL && errno == ERANGE)
{ {
if (!scratch_buffer_grow (&tmpbuf)) if (!scratch_buffer_grow (&tmpbuf))
return 0; return 0;