From patchwork Mon Mar 24 14:04:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 244 X-Patchwork-Delegate: siddhesh@gotplt.org Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx22.g.dreamhost.com (caibbdcaabij.dreamhost.com [208.113.200.189]) by wilcox.dreamhost.com (Postfix) with ESMTP id 22C803600C2 for ; Mon, 24 Mar 2014 07:04:30 -0700 (PDT) Received: by homiemail-mx22.g.dreamhost.com (Postfix, from userid 14307373) id C656151D0570; Mon, 24 Mar 2014 07:04:29 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx22.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx22.g.dreamhost.com (Postfix) with ESMTPS id A100151D0566 for ; Mon, 24 Mar 2014 07:04:29 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=hEtsO3b462eAE9lxR75o0g+uuBZqK 6TQLUdD4ngRjXXw3S37kHeeVrxrUl4li+orefZHZpWdEwI54hZ58iIupWMBt4H+6 NVqbwyiWnLcnbN1j7dc4FXkN2REXuXIksYWyLBamOV6j038wIlsUIHHBdJaOiZJU Em5D9SKFopsw+k= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=m053Gzi6bRzpiDNKBacgq7F9+98=; b=V1y u5UfKuW5xQnRSd6ajmN/a9mHwZNDqftrWJaqqFxZ0myNzgf8gqP1R/Y+QwjyrVbr ZG++x+5mzNq47xtoN1vOZX3VBQhyW10Zsyv+/fHrX7gQti4H5AxQeEkZTs4LsDm8 8CFydMx+AYdkoa/cy+cLOSEGiK7O4qqFKdnmCggI= Received: (qmail 3181 invoked by alias); 24 Mar 2014 14:04:27 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 3168 invoked by uid 89); 24 Mar 2014 14:04:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx2.suse.de From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] Account for alloca use when collecting interface addresses X-Yow: It's NO USE.. I've gone to ``CLUB MED''!! Date: Mon, 24 Mar 2014 15:04:23 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-DH-Original-To: glibc@patchwork.siddhesh.in # ip li add name dummy0 type dummy # site_id=$(head -c6 /dev/urandom | od -tx2 -An | tr ' ' ':') # for ((i = 0; i < 65536; i++)) do > ip ad ad $(printf fd80$site_id::%04x $i)/128 dev dummy0 > done # (ulimit -s 900; getent ahosts localhost) # ip li de dummy0 [BZ #16002] * sysdeps/unix/sysv/linux/check_pf.c (make_request): Use alloca_account and account alloca use for struct in6ailist. --- sysdeps/unix/sysv/linux/check_pf.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/sysdeps/unix/sysv/linux/check_pf.c b/sysdeps/unix/sysv/linux/check_pf.c index 5c8e75a..6d8468d 100644 --- a/sysdeps/unix/sysv/linux/check_pf.c +++ b/sysdeps/unix/sysv/linux/check_pf.c @@ -139,9 +139,10 @@ make_request (int fd, pid_t pid) #endif bool use_malloc = false; char *buf; + size_t alloca_used = 0; if (__libc_use_alloca (buf_size)) - buf = alloca (buf_size); + buf = alloca_account (buf_size, alloca_used); else { buf = malloc (buf_size); @@ -163,6 +164,7 @@ make_request (int fd, pid_t pid) { struct in6addrinfo info; struct in6ailist *next; + bool use_malloc; } *in6ailist = NULL; size_t in6ailistlen = 0; bool seen_ipv4 = false; @@ -239,7 +241,19 @@ make_request (int fd, pid_t pid) } } - struct in6ailist *newp = alloca (sizeof (*newp)); + struct in6ailist *newp; + if (__libc_use_alloca (alloca_used + sizeof (*newp))) + { + newp = alloca_account (sizeof (*newp), alloca_used); + newp->use_malloc = false; + } + else + { + newp = malloc (sizeof (*newp)); + if (newp == NULL) + goto out_fail; + newp->use_malloc = true; + } newp->info.flags = (((ifam->ifa_flags & (IFA_F_DEPRECATED | IFA_F_OPTIMISTIC)) @@ -286,7 +300,10 @@ make_request (int fd, pid_t pid) do { result->in6ai[--in6ailistlen] = in6ailist->info; - in6ailist = in6ailist->next; + struct in6ailist *next = in6ailist->next; + if (in6ailist->use_malloc) + free (in6ailist); + in6ailist = next; } while (in6ailist != NULL); } @@ -302,7 +319,14 @@ make_request (int fd, pid_t pid) free (buf); return result; -out_fail: + out_fail: + while (in6ailist != NULL) + { + struct in6ailist *next = in6ailist->next; + if (in6ailist->use_malloc) + free (in6ailist); + in6ailist = next; + } if (use_malloc) free (buf); return NULL;