2 # Backport from upstream:
4 # From 1cef1b19089528db11f221e938f60b9b048945d7 Mon Sep 17 00:00:00 2001
5 # From: Andreas Schwab <schwab@suse.de>
6 # Date: Thu, 21 Mar 2013 15:50:27 +0100
7 # Subject: [PATCH] Fix stack overflow in getaddrinfo with many results
10 # ChangeLog | 6 ++++++
12 # sysdeps/posix/getaddrinfo.c | 23 +++++++++++++++++++++--
13 # 3 files changed, 31 insertions(+), 3 deletions(-)
15 # 2013-04-03 Andreas Schwab <schwab@suse.de>
18 # * sysdeps/posix/getaddrinfo.c (getaddrinfo): Allocate results and
19 # order arrays from heap if bigger than alloca cutoff.
21 diff -urN glibc-2.12-2-gc4ccff1.orig/sysdeps/posix/getaddrinfo.c glibc-2.12-2-gc4ccff1/sysdeps/posix/getaddrinfo.c
22 --- glibc-2.12-2-gc4ccff1.orig/sysdeps/posix/getaddrinfo.c 2013-07-24 20:40:37.601887975 -0400
23 +++ glibc-2.12-2-gc4ccff1/sysdeps/posix/getaddrinfo.c 2013-07-24 20:54:32.722447705 -0400
24 @@ -2386,11 +2386,27 @@
25 __typeof (once) old_once = once;
26 __libc_once (once, gaiconf_init);
27 /* Sort results according to RFC 3484. */
28 - struct sort_result results[nresults];
29 - size_t order[nresults];
30 + struct sort_result *results;
33 struct addrinfo *last = NULL;
34 char *canonname = NULL;
35 + bool malloc_results;
38 + = !__libc_use_alloca (nresults * (sizeof (*results) + sizeof (*order)));
41 + results = malloc (nresults * (sizeof (*results) + sizeof (*order)));
42 + if (results == NULL)
49 + results = alloca (nresults * (sizeof (*results) + sizeof (*order)));
50 + order = (size_t *) (results + nresults);
52 /* If we have information about deprecated and temporary addresses
53 sort the array now. */
56 /* Fill in the canonical name into the new first entry. */
57 p->ai_canonname = canonname;