]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix stack overflow in getaddrinfo with many results ibm/2.16/master
authorAndreas Schwab <schwab@suse.de>
Thu, 21 Mar 2013 14:50:27 +0000 (15:50 +0100)
committerTulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>
Mon, 13 Apr 2015 20:39:37 +0000 (17:39 -0300)
Conflicts:
NEWS

ChangeLog
NEWS
sysdeps/posix/getaddrinfo.c

index 246f0a51840d839a37dbc264958c98cc5b6e6673..b6ef28d738cf1697abeeb0f9364c14f2af4b777b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-04-03  Andreas Schwab  <schwab@suse.de>
+
+       [BZ #15330]
+       * sysdeps/posix/getaddrinfo.c (getaddrinfo): Allocate results and
+       order arrays from heap if bigger than alloca cutoff.
+
 2014-06-03  Andreas Schwab  <schwab@suse.de>
 
        [BZ #15946]
diff --git a/NEWS b/NEWS
index 6a49b4bdb550b0392c14694f0e31b1da5397f2f5..2b31faa0ea7b6a18151566dfcf26e6977aab96d3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,8 +10,11 @@ Version 2.16.1
 * The following bugs are resolved with this release:
 
   6530, 14195, 14547, 14459, 14476, 14562, 14621, 14648, 14699, 14719,
-  14756, 14831, 15014, 15078, 15754, 15755, 15946, 16072, 16431, 16617,
-  16618, 17048, 17137, 17187, 17325, 17625, 17630.
+  14756, 14831, 15014, 15078, 15330, 15754, 15755, 15946, 16072, 16431,
+  16617, 16618, 17048, 17137, 17187, 17325, 17625, 17630.
+
+* CVE-2013-1914 Stack overflow in getaddrinfo with many results has been
+  fixed (Bugzilla #15330).
 
 * CVE-2104-7817 The wordexp function could ignore the WRDE_NOCMD flag
   under certain input conditions resulting in the execution of a shell for
index dd8513055456e2316e817ef9023e35b0ce6eff0b..c88e1ec00552936f4997f99d878f539ab95beb8c 100644 (file)
@@ -2467,11 +2467,27 @@ getaddrinfo (const char *name, const char *service,
       __typeof (once) old_once = once;
       __libc_once (once, gaiconf_init);
       /* Sort results according to RFC 3484.  */
-      struct sort_result results[nresults];
-      size_t order[nresults];
+      struct sort_result *results;
+      size_t *order;
       struct addrinfo *q;
       struct addrinfo *last = NULL;
       char *canonname = NULL;
+      bool malloc_results;
+
+      malloc_results
+       = !__libc_use_alloca (nresults * (sizeof (*results) + sizeof (size_t)));
+      if (malloc_results)
+       {
+         results = malloc (nresults * (sizeof (*results) + sizeof (size_t)));
+         if (results == NULL)
+           {
+             __free_in6ai (in6ai);
+             return EAI_MEMORY;
+           }
+       }
+      else
+       results = alloca (nresults * (sizeof (*results) + sizeof (size_t)));
+      order = (size_t *) (results + nresults);
 
       /* Now we definitely need the interface information.  */
       if (! check_pf_called)
@@ -2642,6 +2658,9 @@ getaddrinfo (const char *name, const char *service,
 
       /* Fill in the canonical name into the new first entry.  */
       p->ai_canonname = canonname;
+
+      if (malloc_results)
+       free (results);
     }
 
   __free_in6ai (in6ai);