From 16fe069433d6c5349680050ec54e3826ecef7c4d Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Mon, 20 Dec 2021 00:34:58 +0100 Subject: Fix certain combinations of regex range quantifiers Fix regex transitions that have both min/max and a counter. In this case, we want to save the regex state before incrementing the counter. Fixes #301 and the issue reported here: https://mail.gnome.org/archives/xml/2016-April/msg00017.html --- result/regexp/issue301 | 4 ++++ test/regexp/issue301 | 4 ++++ xmlregexp.c | 11 ++++++----- 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 result/regexp/issue301 create mode 100644 test/regexp/issue301 diff --git a/result/regexp/issue301 b/result/regexp/issue301 new file mode 100644 index 00000000..90e7c4c0 --- /dev/null +++ b/result/regexp/issue301 @@ -0,0 +1,4 @@ +Regexp: (a{1,2}|ab){2} +abab: Ok +Regexp: ((1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5]) +192.168.254.0: Ok diff --git a/test/regexp/issue301 b/test/regexp/issue301 new file mode 100644 index 00000000..b5a316b1 --- /dev/null +++ b/test/regexp/issue301 @@ -0,0 +1,4 @@ +=>(a{1,2}|ab){2} +abab +=>((1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5]) +192.168.254.0 diff --git a/xmlregexp.c b/xmlregexp.c index 95aebf1f..5816aa82 100644 --- a/xmlregexp.c +++ b/xmlregexp.c @@ -3364,7 +3364,6 @@ xmlFARegExec(xmlRegexpPtr comp, const xmlChar *content) { /* * this is a multiple input sequence * If there is a counter associated increment it now. - * before potentially saving and rollback * do not increment if the counter is already over the * maximum limit in which case get to next transition */ @@ -3380,15 +3379,17 @@ xmlFARegExec(xmlRegexpPtr comp, const xmlChar *content) { counter = &exec->comp->counters[trans->counter]; if (exec->counts[trans->counter] >= counter->max) continue; /* for loop on transitions */ - + } + /* Save before incrementing */ + if (exec->state->nbTrans > exec->transno + 1) { + xmlFARegExecSave(exec); + } + if (trans->counter >= 0) { #ifdef DEBUG_REGEXP_EXEC printf("Increasing count %d\n", trans->counter); #endif exec->counts[trans->counter]++; } - if (exec->state->nbTrans > exec->transno + 1) { - xmlFARegExecSave(exec); - } exec->transcount = 1; do { /* -- cgit v1.2.1