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