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