From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2206) id 26F2E3858D20; Tue, 1 Mar 2022 02:40:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26F2E3858D20 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Siddhesh Poyarekar To: glibc-cvs@sourceware.org Subject: [glibc/siddhesh/gai-cleanup2] gaih_inet: Fix leak with AF_INET6 and AI_ALL [BZ #28852] X-Act-Checkin: glibc X-Git-Author: Siddhesh Poyarekar X-Git-Refname: refs/heads/siddhesh/gai-cleanup2 X-Git-Oldrev: 6e70668051767f146eeaad1bbe184a3092944892 X-Git-Newrev: 38454ba670d978ee9a33fdbdab4f80bdd611907b Message-Id: <20220301024057.26F2E3858D20@sourceware.org> Date: Tue, 1 Mar 2022 02:40:57 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Mar 2022 02:40:57 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=38454ba670d978ee9a33fdbdab4f80bdd611907b commit 38454ba670d978ee9a33fdbdab4f80bdd611907b Author: Siddhesh Poyarekar Date: Mon Feb 28 20:39:02 2022 +0530 gaih_inet: Fix leak with AF_INET6 and AI_ALL [BZ #28852] Resolves: BZ #28852 Signed-off-by: Siddhesh Poyarekar Diff: --- sysdeps/posix/getaddrinfo.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 010360986a..0173397fe1 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -243,8 +243,7 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, struct hostent *h, struct gaih_addrtuple **result) { - while (*result) - result = &(*result)->next; + assert (*result == NULL); /* Count the number of addresses in h->h_addr_list. */ size_t count = 0; @@ -319,14 +318,22 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, } \ else if (status == NSS_STATUS_SUCCESS) \ { \ + struct gaih_addrtuple *addrmem = NULL; \ if (!convert_hostent_to_gaih_addrtuple (req, _family, &th, &addrmem)) \ { \ __resolv_context_put (res_ctx); \ result = -EAI_SYSTEM; \ goto free_and_return; \ } \ + if (addrmem && !gaih_lookup_result_push_alloc (&res, addrmem)) \ + { \ + free (addrmem); \ + result = -EAI_MEMORY; \ + goto free_and_return; \ + } \ *pat = addrmem; \ - \ + while (*pat != NULL) \ + pat = &((*pat)->next); \ if (localcanon != NULL && canon == NULL) \ { \ canonbuf = __strdup (localcanon); \ @@ -338,7 +345,7 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, } \ canon = canonbuf; \ } \ - if (_family == AF_INET6 && *pat != NULL) \ + if (_family == AF_INET6 && addrmem != NULL) \ got_ipv6 = true; \ } \ } @@ -783,7 +790,6 @@ gaih_inet (const char *name, const struct gaih_service *service, return rc; bool malloc_name = false; - struct gaih_addrtuple *addrmem = NULL; char *canonbuf = NULL; int result = 0; struct gaih_lookup_result res = {0}; @@ -1228,7 +1234,6 @@ gaih_inet (const char *name, const struct gaih_service *service, free_and_return: if (malloc_name) free ((char *) name); - free (addrmem); free (canonbuf); gaih_lookup_result_free (&res); scratch_buffer_free (&resbuf);