From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11299 invoked by alias); 19 Sep 2018 20:52:00 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 11287 invoked by uid 89); 19 Sep 2018 20:51:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=herr X-HELO: mx1.redhat.com From: Florian Weimer To: Mingli Yu Cc: libc-alpha@sourceware.org Subject: [PATCH] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679] Date: Wed, 19 Sep 2018 20:52:00 -0000 Message-ID: <87zhwdjjmd.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2018-09/txt/msg00335.txt.bz2 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 * 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;