From patchwork Sun Mar 1 15:14:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 444979 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 9BF0E1400EA for ; Mon, 2 Mar 2015 19:57:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=sourceware.org header.i=@sourceware.org header.b=ARGXLKBQ; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:in-reply-to:references:from:date :subject:to; q=dns; s=default; b=SHrRn5Sb71YPIbYey8LP39eucLObpjM VXH0ub0ONsMJcyd/0PC0iiGL/q7ifIUQ6kkFOyqyyxsLAn/NxlzU3kofB/7uu6U0 5HwpZAErxUKJgID1qg5+/Or91CjZ0hUAx4vdzLuSptIZL4mVSfp5wke9HNp0BcTF iXh5kxxN0N+M= 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:message-id:in-reply-to:references:from:date :subject:to; s=default; bh=dqUzYa8RIeRDI18KVHNh9VzljLA=; b=ARGXL KBQLFqEQY2KyZ3CxlOc7LBM2YXx3EjjGdYvHbWpSbdV14LpPBb5CBE6edC9Q1e5B FKKJVDC/mic1tPGzbHDRLVM74gU+yLY66Hum88saxEfDes+3aUHYtMu2c7Ch6JJ0 v/4lA+EPNBkiOuETdwQxN9f+D9Y3f4DEXBAdWs= Received: (qmail 117228 invoked by alias); 2 Mar 2015 08:56:40 -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 117110 invoked by uid 89); 2 Mar 2015 08:56:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_50, DATE_IN_PAST_12_24, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Message-Id: <605fe16633894ab34c5e63a22a40de78a1c908c5.1425285061.git.fweimer@redhat.com> In-Reply-To: References: From: Florian Weimer Date: Sun, 1 Mar 2015 16:14:12 +0100 Subject: [PATCH 11/25] _nss_compat_initgroups_dyn: Use struct scratch_buffer instead of extend_alloca To: libc-alpha@sourceware.org --- nis/nss_compat/compat-initgroups.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/nis/nss_compat/compat-initgroups.c b/nis/nss_compat/compat-initgroups.c index 5e6f970..795298e 100644 --- a/nis/nss_compat/compat-initgroups.c +++ b/nis/nss_compat/compat-initgroups.c @@ -16,7 +16,6 @@ License along with the GNU C Library; if not, see . */ -#include #include #include #include @@ -30,6 +29,7 @@ #include #include #include +#include static service_user *ni; /* Type of the lookup function. */ @@ -524,46 +524,31 @@ _nss_compat_initgroups_dyn (const char *user, gid_t group, long int *start, long int *size, gid_t **groupsp, long int limit, int *errnop) { - size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX); - char *tmpbuf; enum nss_status status; ent_t intern = { true, false, false, NULL, {NULL, 0, 0} }; - bool use_malloc = false; status = internal_setgrent (&intern); if (status != NSS_STATUS_SUCCESS) return status; - tmpbuf = __alloca (buflen); + struct scratch_buffer tmpbuf; + scratch_buffer_init (&tmpbuf); do { - while ((status = internal_getgrent_r (&intern, tmpbuf, buflen, + while ((status = internal_getgrent_r (&intern, tmpbuf.data, tmpbuf.length, user, group, start, size, groupsp, limit, errnop)) == NSS_STATUS_TRYAGAIN && *errnop == ERANGE) - if (__libc_use_alloca (buflen * 2)) - tmpbuf = extend_alloca (tmpbuf, buflen, 2 * buflen); - else - { - buflen *= 2; - char *newbuf = realloc (use_malloc ? tmpbuf : NULL, buflen); - if (newbuf == NULL) - { - status = NSS_STATUS_TRYAGAIN; - goto done; - } - use_malloc = true; - tmpbuf = newbuf; - } + if (!scratch_buffer_grow (&tmpbuf)) + goto done; } while (status == NSS_STATUS_SUCCESS); status = NSS_STATUS_SUCCESS; done: - if (use_malloc) - free (tmpbuf); + scratch_buffer_free (&tmpbuf); internal_endgrent (&intern);