From patchwork Fri Dec 8 09:16:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnold Robbins X-Patchwork-Id: 24798 Received: (qmail 96836 invoked by alias); 8 Dec 2017 09:20:29 -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 96179 invoked by uid 89); 8 Dec 2017 09:19:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, MANY_HDRS_LCASE, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=HContent-type:text X-HELO: mxout4.netvision.net.il MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII From: Arnold Robbins Message-id: <201712080916.vB89GxVP005493@skeeve.com> Date: Fri, 08 Dec 2017 11:16:59 +0200 To: carlos@redhat.com, libc-alpha@sourceware.org Subject: [PATCH 02/17] Regex: Fix alloca ifdefs and usage. User-Agent: Heirloom mailx 12.5 6/20/10 This patch cleans up the use of alloca, making sure includes and uses are inside the proper ifdef, and replacing use of alloca with more standard constructs where that works. Missing ifdefs are added. 2017-11-27 Arnold D. Robbins * posix/regcomp.c (re_compile_fastmap_iter): Replace alloca call with allocation on the stack. * posix/regex_internal.h: Fix HAVE_ALLOCA and add it where needed. * posix/regexec.c (set_regs): Ditto. (build_trtable): Ditto. diff --git a/posix/regcomp.c b/posix/regcomp.c index 6bc4102..5bb1d11 100644 --- a/posix/regcomp.c +++ b/posix/regcomp.c @@ -317,7 +317,8 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, #ifdef RE_ENABLE_I18N if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1) { - unsigned char *buf = alloca (dfa->mb_cur_max), *p; + unsigned char buf[MB_LEN_MAX]; + unsigned char *p; wchar_t wc; mbstate_t state; diff --git a/posix/regex_internal.h b/posix/regex_internal.h index fef1d35..79e438a 100644 --- a/posix/regex_internal.h +++ b/posix/regex_internal.h @@ -402,10 +402,9 @@ static unsigned int re_string_context_at (const re_string_t *input, int idx, #define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx)) #define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx)) -#include - #ifndef _LIBC # if HAVE_ALLOCA +# include /* The OS usually guarantees only one guard page at the bottom of the stack, and a page size can be as small as 4096 bytes. So we cannot safely allocate anything larger than 4096 bytes. Also care for the possibility diff --git a/posix/regexec.c b/posix/regexec.c index 95e31d3..1290576 100644 --- a/posix/regexec.c +++ b/posix/regexec.c @@ -1383,9 +1383,11 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, cur_node = dfa->init_node; re_node_set_init_empty (&eps_via_nodes); +#ifdef HAVE_ALLOCA if (__libc_use_alloca (nmatch * sizeof (regmatch_t))) prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t)); else +#endif { prev_idx_match = re_malloc (regmatch_t, nmatch); if (prev_idx_match == NULL) @@ -3269,9 +3271,11 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) from `state'. `dests_node[i]' represents the nodes which i-th destination state contains, and `dests_ch[i]' represents the characters which i-th destination state accepts. */ +#ifdef HAVE_ALLOCA if (__libc_use_alloca (sizeof (struct dests_alloc))) dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc)); else +#endif { dests_alloc = re_malloc (struct dests_alloc, 1); if (BE (dests_alloc == NULL, 0)) @@ -3314,11 +3318,13 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) 0)) goto out_free; +#ifdef HAVE_ALLOCA if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX + ndests * 3 * sizeof (re_dfastate_t *))) dest_states = (re_dfastate_t **) alloca (ndests * 3 * sizeof (re_dfastate_t *)); else +#endif { dest_states = (re_dfastate_t **) malloc (ndests * 3 * sizeof (re_dfastate_t *));