From patchwork Sun Mar 1 15:08:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 444973 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 4639514009B for ; Mon, 2 Mar 2015 19:43:25 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=sourceware.org header.i=@sourceware.org header.b=i2J13sRX; 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=lMhd/vIEirChej/mwXuUjRTEJZlYDPg JSYtJ0xF5UcVt+Nl6E3VUvyRnT0afxTFREvkiyGt8G6d86GhN8qHKr38svvetVEB z3JlbUPWAxeXoOTPHbbus6e1QjrlqM8jEuTHq7hvvgSuzortVub1IRQCce5Ihw8j pPX00BplPD0s= 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=oPuQeVzueF+EAQvabc1TJ164J88=; b=i2J13 sRXr0ERyzH8Yz8XT9fIOt7aCO/P0EZw6pe7yTQZON/S0X4KoHQrWaDJ8iKk2iK17 etTcHJ02RtsBXqwM6Sd26H9siONb3qOhaWx97SaOBk/JoFQ8TtsyujjrVpG5aXCc Rjnt/2O2m+cGH0CQGIy+jZDkehACR2TEar7UNQ= Received: (qmail 90961 invoked by alias); 2 Mar 2015 08:43:10 -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 90902 invoked by uid 89); 2 Mar 2015 08:43:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL, BAYES_50, DATE_IN_PAST_12_24, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Message-Id: In-Reply-To: References: From: Florian Weimer Date: Sun, 1 Mar 2015 16:08:58 +0100 Subject: [PATCH 09/25] grp: Rewrite to use struct scratch_buffer instead of extend_alloca To: libc-alpha@sourceware.org grp/compat-initgroups.c is included from nscd/initgrcache.c, which is why the #include directive has to be added there as well. --- grp/compat-initgroups.c | 26 ++++++++------------------ grp/initgroups.c | 2 +- nscd/initgrcache.c | 1 + 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/grp/compat-initgroups.c b/grp/compat-initgroups.c index ff10e24..3dd50d2 100644 --- a/grp/compat-initgroups.c +++ b/grp/compat-initgroups.c @@ -14,7 +14,6 @@ compat_call (service_user *nip, const char *user, gid_t group, long int *start, long int *size, gid_t **groupsp, long int limit, int *errnop) { struct group grpbuf; - size_t buflen = __sysconf (_SC_GETGR_R_SIZE_MAX); enum nss_status status; set_function setgrent_fct; get_function getgrent_fct; @@ -35,30 +34,22 @@ compat_call (service_user *nip, const char *user, gid_t group, long int *start, endgrent_fct = __nss_lookup_function (nip, "endgrent"); - char *tmpbuf = __alloca (buflen); - bool use_malloc = false; + struct scratch_buffer tmpbuf; + scratch_buffer_init (&tmpbuf); enum nss_status result = NSS_STATUS_SUCCESS; do { while ((status = DL_CALL_FCT (getgrent_fct, - (&grpbuf, tmpbuf, buflen, errnop)), + (&grpbuf, tmpbuf.data, tmpbuf.length, + errnop)), status == NSS_STATUS_TRYAGAIN) && *errnop == ERANGE) { - if (__libc_use_alloca (buflen * 2)) - tmpbuf = extend_alloca (tmpbuf, buflen, buflen * 2); - else + if (!scratch_buffer_grow (&tmpbuf)) { - buflen *= 2; - char *newbuf = realloc (use_malloc ? tmpbuf : NULL, buflen); - if (newbuf == NULL) - { - result = NSS_STATUS_TRYAGAIN; - goto done; - } - use_malloc = true; - tmpbuf = newbuf; + result = NSS_STATUS_TRYAGAIN; + goto done; } } @@ -116,8 +107,7 @@ compat_call (service_user *nip, const char *user, gid_t group, long int *start, while (status == NSS_STATUS_SUCCESS); done: - if (use_malloc) - free (tmpbuf); + scratch_buffer_free (&tmpbuf); if (endgrent_fct) DL_CALL_FCT (endgrent_fct, ()); diff --git a/grp/initgroups.c b/grp/initgroups.c index 4d083ac..14a8ab1 100644 --- a/grp/initgroups.c +++ b/grp/initgroups.c @@ -15,7 +15,6 @@ License along with the GNU C Library; if not, see . */ -#include #include #include #include @@ -26,6 +25,7 @@ #include #include #include +#include #include "../nscd/nscd-client.h" #include "../nscd/nscd_proto.h" diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c index 7ba76be..e45d65c 100644 --- a/nscd/initgrcache.c +++ b/nscd/initgrcache.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "dbg_log.h" #include "nscd.h"