From 1214ba06e6771acb953a190091b0f6055c64fd25 Mon Sep 17 00:00:00 2001 From: Mingli Yu Date: Thu, 20 Sep 2018 12:02:48 +0200 Subject: Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679] A NULL value can happen with certain gethostbyname_r failures. --- sysdeps/unix/sysv/linux/gethostid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sysdeps/unix/sysv/linux/gethostid.c') 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; -- cgit 1.4.1