From 39e65294a4bf06e7dda676945bf3a6f73075ad47 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Wed, 25 Mar 2015 18:25:09 +0000 Subject: [PATCH] regex: fix character class repetitions Internally regcomp needs to copy some iteration nodes before translating the AST into TNFA representation. Literal nodes were not copied correctly: the class type and list of negated class types were not copied so classes were ignored (in the non-negated case an ignored char class caused the literal to match everything). This affects iterations when the upper bound is finite, larger than one or the lower bound is larger than one. So eg. the EREs [[:digit:]]{2} [^[:space:]ab]{1,4} were treated as .{2} [^ab]{1,4} The fix is done with minimal source modification to copy the necessary fields, but the AST preparation and node handling code of tre will need to be cleaned up for clarity. (cherry picked from commit c498efe117539a9d40d90b588c033316701c4b3e) --- src/regex/regcomp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c index 01d42a8e..33213257 100644 --- a/src/regex/regcomp.c +++ b/src/regex/regcomp.c @@ -2139,6 +2139,11 @@ tre_copy_ast(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *ast, *result = tre_ast_new_literal(mem, min, max, pos); if (*result == NULL) status = REG_ESPACE; + else { + tre_literal_t *p = (*result)->obj; + p->class = lit->class; + p->neg_classes = lit->neg_classes; + } if (pos > *max_pos) *max_pos = pos; -- 2.25.1