|
|
147e83 |
commit 1cef1b19089528db11f221e938f60b9b048945d7
|
|
|
147e83 |
Author: Andreas Schwab <schwab@suse.de>
|
|
|
147e83 |
Date: Thu Mar 21 15:50:27 2013 +0100
|
|
|
147e83 |
|
|
|
147e83 |
Fix stack overflow in getaddrinfo with many results
|
|
|
147e83 |
|
|
|
147e83 |
diff --git glibc-2.17-c758a686/sysdeps/posix/getaddrinfo.c glibc-2.17-c758a686/sysdeps/posix/getaddrinfo.c
|
|
|
147e83 |
index d95c2d1..2309281 100644
|
|
|
147e83 |
--- glibc-2.17-c758a686/sysdeps/posix/getaddrinfo.c
|
|
|
147e83 |
+++ glibc-2.17-c758a686/sysdeps/posix/getaddrinfo.c
|
|
|
147e83 |
@@ -2489,11 +2489,27 @@ getaddrinfo (const char *name, const char *service,
|
|
|
147e83 |
__typeof (once) old_once = once;
|
|
|
147e83 |
__libc_once (once, gaiconf_init);
|
|
|
147e83 |
/* Sort results according to RFC 3484. */
|
|
|
147e83 |
- struct sort_result results[nresults];
|
|
|
147e83 |
- size_t order[nresults];
|
|
|
147e83 |
+ struct sort_result *results;
|
|
|
147e83 |
+ size_t *order;
|
|
|
147e83 |
struct addrinfo *q;
|
|
|
147e83 |
struct addrinfo *last = NULL;
|
|
|
147e83 |
char *canonname = NULL;
|
|
|
147e83 |
+ bool malloc_results;
|
|
|
147e83 |
+
|
|
|
147e83 |
+ malloc_results
|
|
|
147e83 |
+ = !__libc_use_alloca (nresults * (sizeof (*results) + sizeof (size_t)));
|
|
|
147e83 |
+ if (malloc_results)
|
|
|
147e83 |
+ {
|
|
|
147e83 |
+ results = malloc (nresults * (sizeof (*results) + sizeof (size_t)));
|
|
|
147e83 |
+ if (results == NULL)
|
|
|
147e83 |
+ {
|
|
|
147e83 |
+ __free_in6ai (in6ai);
|
|
|
147e83 |
+ return EAI_MEMORY;
|
|
|
147e83 |
+ }
|
|
|
147e83 |
+ }
|
|
|
147e83 |
+ else
|
|
|
147e83 |
+ results = alloca (nresults * (sizeof (*results) + sizeof (size_t)));
|
|
|
147e83 |
+ order = (size_t *) (results + nresults);
|
|
|
147e83 |
|
|
|
147e83 |
/* Now we definitely need the interface information. */
|
|
|
147e83 |
if (! check_pf_called)
|
|
|
147e83 |
@@ -2664,6 +2680,9 @@ getaddrinfo (const char *name, const char *service,
|
|
|
147e83 |
|
|
|
147e83 |
/* Fill in the canonical name into the new first entry. */
|
|
|
147e83 |
p->ai_canonname = canonname;
|
|
|
147e83 |
+
|
|
|
147e83 |
+ if (malloc_results)
|
|
|
147e83 |
+ free (results);
|
|
|
147e83 |
}
|
|
|
147e83 |
|
|
|
147e83 |
__free_in6ai (in6ai);
|