From patchwork Sun Mar 1 17:45:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 5402 Received: (qmail 116899 invoked by alias); 2 Mar 2015 08:56:38 -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 116884 invoked by uid 89); 2 Mar 2015 08:56:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, 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: In-Reply-To: References: From: Florian Weimer Date: Sun, 1 Mar 2015 18:45:17 +0100 Subject: [PATCH 13/25] nscd_getgr_r: Use struct scratch_buffer instead of extend_alloca To: libc-alpha@sourceware.org The lack of alloca accounting means that the old code could run out of stack space if multiple retries are needed. --- nscd/nscd_getgr_r.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/nscd/nscd_getgr_r.c b/nscd/nscd_getgr_r.c index 7e45ee5..d08b73f 100644 --- a/nscd/nscd_getgr_r.c +++ b/nscd/nscd_getgr_r.c @@ -31,6 +31,7 @@ #include #include #include <_itoa.h> +#include #include "nscd-client.h" #include "nscd_proto.h" @@ -89,7 +90,8 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, int gc_cycle; int nretries = 0; const uint32_t *len = NULL; - size_t lensize = 0; + struct scratch_buffer lenbuf; + scratch_buffer_init (&lenbuf); /* If the mapping is available, try to search there instead of communicating with the nscd. */ @@ -200,14 +202,10 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, else { /* Allocate array to store lengths. */ - if (lensize == 0) - { - lensize = gr_resp.gr_mem_cnt * sizeof (uint32_t); - len = (uint32_t *) alloca (lensize); - } - else if (gr_resp.gr_mem_cnt * sizeof (uint32_t) > lensize) - len = extend_alloca (len, lensize, - gr_resp.gr_mem_cnt * sizeof (uint32_t)); + if (!scratch_buffer_set_array_size + (&lenbuf, gr_resp.gr_mem_cnt, sizeof (uint32_t))) + goto out_close; + len = lenbuf.data; vec[0].iov_base = (void *) len; vec[0].iov_len = gr_resp.gr_mem_cnt * sizeof (uint32_t); @@ -326,5 +324,7 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, goto retry; } + scratch_buffer_free (&lenbuf); + return retval; }