From ed885487570a4a0046b0cb32a477526f8f016d93 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Wed, 19 Feb 2014 21:14:44 -0700 Subject: [PATCH] regcomp.c: Don't read uninitialized data I keep forgetting that the OP of a regnode is not defined in Pass 1 of the regex compiler. This is likely the cause of inconsistent results in lib/locale.t, as valgrind shows there to be a read of uninitialized data before this patch, and the result is randomly tainting when there shouldn't be, consistent with the test failures. --- embed.fnc | 2 +- proto.h | 2 +- regcomp.c | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/embed.fnc b/embed.fnc index d0943e8..f747aae 100644 --- a/embed.fnc +++ b/embed.fnc @@ -2079,7 +2079,7 @@ EsRn |char * |regpatws |NN RExC_state_t *pRExC_state \ |NN char *p|const bool recognize_comment Ei |void |alloc_maybe_populate_EXACT|NN RExC_state_t *pRExC_state \ |NN regnode *node|NN I32 *flagp|STRLEN len \ - |UV code_point|const bool downgradable + |UV code_point|bool downgradable Ei |U8 |compute_EXACTish|NN RExC_state_t *pRExC_state Es |char * |nextchar |NN RExC_state_t *pRExC_state Es |bool |reg_skipcomment|NN RExC_state_t *pRExC_state diff --git a/proto.h b/proto.h index 4832535..e032ad6 100644 --- a/proto.h +++ b/proto.h @@ -6607,7 +6607,7 @@ STATIC U32 S_add_data(RExC_state_t* const pRExC_state, const char* const s, cons #define PERL_ARGS_ASSERT_ADD_DATA \ assert(pRExC_state); assert(s) -PERL_STATIC_INLINE void S_alloc_maybe_populate_EXACT(pTHX_ RExC_state_t *pRExC_state, regnode *node, I32 *flagp, STRLEN len, UV code_point, const bool downgradable) +PERL_STATIC_INLINE void S_alloc_maybe_populate_EXACT(pTHX_ RExC_state_t *pRExC_state, regnode *node, I32 *flagp, STRLEN len, UV code_point, bool downgradable) __attribute__nonnull__(pTHX_1) __attribute__nonnull__(pTHX_2) __attribute__nonnull__(pTHX_3); diff --git a/regcomp.c b/regcomp.c index b3a4845..efd0a47 100644 --- a/regcomp.c +++ b/regcomp.c @@ -10882,7 +10882,7 @@ S_compute_EXACTish(pTHX_ RExC_state_t *pRExC_state) PERL_STATIC_INLINE void S_alloc_maybe_populate_EXACT(pTHX_ RExC_state_t *pRExC_state, regnode *node, I32* flagp, STRLEN len, UV code_point, - const bool downgradable) + bool downgradable) { /* This knows the details about sizing an EXACTish node, setting flags for * it (by setting <*flagp>, and potentially populating it with a single @@ -10916,6 +10916,12 @@ S_alloc_maybe_populate_EXACT(pTHX_ RExC_state_t *pRExC_state, PERL_ARGS_ASSERT_ALLOC_MAYBE_POPULATE_EXACT; + /* Don't bother to check for downgrading in PASS1, as it doesn't make any + * sizing difference, and is extra work that is thrown away */ + if (downgradable && ! PASS2) { + downgradable = FALSE; + } + if (! len_passed_in) { if (UTF) { if (UNI_IS_INVARIANT(code_point)) { @@ -11020,7 +11026,8 @@ S_alloc_maybe_populate_EXACT(pTHX_ RExC_state_t *pRExC_state, *flagp |= SIMPLE; } - if (OP(node) == EXACTFL) { + /* The OP may not be well defined in PASS1 */ + if (PASS2 && OP(node) == EXACTFL) { RExC_contains_locale = 1; } } -- 2.7.4