public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/siddhesh/gai-cleanup2] gaih_inet: Fix leak with AF_INET6 and AI_ALL
@ 2022-02-23 10:07 Siddhesh Poyarekar
  0 siblings, 0 replies; 2+ messages in thread
From: Siddhesh Poyarekar @ 2022-02-23 10:07 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=68a304c62f76256a640022bd6633b9507a374aab

commit 68a304c62f76256a640022bd6633b9507a374aab
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date:   Wed Feb 23 14:29:24 2022 +0530

    gaih_inet: Fix leak with AF_INET6 and AI_ALL

Diff:
---
 sysdeps/posix/getaddrinfo.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index c00a86e440..f7384dfc07 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -223,8 +223,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;
@@ -299,14 +298,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 (!func_cleanup_push (&allocs, &nallocs, 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);				      \
@@ -318,7 +325,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;						      \
     }									      \
  }
@@ -788,7 +795,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;


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [glibc/siddhesh/gai-cleanup2] gaih_inet: Fix leak with AF_INET6 and AI_ALL
@ 2022-02-23  9:03 Siddhesh Poyarekar
  0 siblings, 0 replies; 2+ messages in thread
From: Siddhesh Poyarekar @ 2022-02-23  9:03 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b3f7d6266f4424fbeb08b4c536a4b90c52c12dde

commit b3f7d6266f4424fbeb08b4c536a4b90c52c12dde
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date:   Wed Feb 23 14:29:24 2022 +0530

    gaih_inet: Fix leak with AF_INET6 and AI_ALL

Diff:
---
 sysdeps/posix/getaddrinfo.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 49b1597f77..903cda9f65 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -223,8 +223,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;
@@ -299,14 +298,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 (!func_cleanup_push (&allocs, &nallocs, 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);				      \
@@ -318,7 +325,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;						      \
     }									      \
  }
@@ -770,7 +777,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;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-23 10:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23 10:07 [glibc/siddhesh/gai-cleanup2] gaih_inet: Fix leak with AF_INET6 and AI_ALL Siddhesh Poyarekar
  -- strict thread matches above, loose matches on Subject: below --
2022-02-23  9:03 Siddhesh Poyarekar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).