From f86d8d35fa49acdfd15c61e825f5a7d051273fa8 Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Mon, 10 Aug 2015 16:34:17 +0000 Subject: [PATCH] Make (*LIMIT_MATCH=) give an error and correct offsets for limit syntax errors. --- ChangeLog | 5 +++++ src/pcre2_compile.c | 7 +++++++ testdata/testinput2 | 4 ++++ testdata/testoutput14 | 4 ++-- testdata/testoutput2 | 6 ++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a0ac44f..ae6f568 100644 --- a/ChangeLog +++ b/ChangeLog @@ -128,6 +128,11 @@ offsets in the pattern. 33. Improve the performance of starting single character repetitions in JIT. +34. (*LIMIT_MATCH=) now gives an error instead of setting the value to 0. + +35. Error messages for syntax errors in *LIMIT_MATCH and *LIMIT_RECURSION now +give the right offset instead of zero. + Version 10.20 30-June-2015 -------------------------- diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index 404ea0c..aa65fd3 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -7941,6 +7941,12 @@ while (ptr[skipatstart] == CHAR_LEFT_PARENTHESIS && case PSO_LIMR: c = 0; pp = skipatstart; + if (!IS_DIGIT(ptr[pp])) + { + errorcode = ERR60; + ptr += pp; + goto HAD_ERROR; + } while (IS_DIGIT(ptr[pp])) { if (c > UINT32_MAX / 10 - 1) break; /* Integer overflow */ @@ -7949,6 +7955,7 @@ while (ptr[skipatstart] == CHAR_LEFT_PARENTHESIS && if (ptr[pp++] != CHAR_RIGHT_PARENTHESIS) { errorcode = ERR60; + ptr += pp; goto HAD_ERROR; } if (p->type == PSO_LIMM) limit_match = c; diff --git a/testdata/testinput2 b/testdata/testinput2 index 20b176a..282cd0d 100644 --- a/testdata/testinput2 +++ b/testdata/testinput2 @@ -4399,4 +4399,8 @@ a random value. /Ix /(?(1)()\983040\2)/ +/(*LIMIT_MATCH=)abc/ + +/(*CRLF)(*LIMIT_MATCH=)abc/ + # End of testinput2 diff --git a/testdata/testoutput14 b/testdata/testoutput14 index 5f8d423..fe012d9 100644 --- a/testdata/testoutput14 +++ b/testdata/testoutput14 @@ -98,10 +98,10 @@ Minimum recursion limit = 10 3: ee /(*LIMIT_MATCH=12bc)abc/ -Failed: error 160 at offset 0: (*VERB) not recognized or malformed +Failed: error 160 at offset 17: (*VERB) not recognized or malformed /(*LIMIT_MATCH=4294967290)abc/ -Failed: error 160 at offset 0: (*VERB) not recognized or malformed +Failed: error 160 at offset 24: (*VERB) not recognized or malformed /(*LIMIT_RECURSION=4294967280)abc/I Capturing subpattern count = 0 diff --git a/testdata/testoutput2 b/testdata/testoutput2 index 40771c1..0c5f44b 100644 --- a/testdata/testoutput2 +++ b/testdata/testoutput2 @@ -14651,4 +14651,10 @@ No match /(?(1)()\983040\2)/ Failed: error 115 at offset 13: reference to non-existent subpattern +/(*LIMIT_MATCH=)abc/ +Failed: error 160 at offset 14: (*VERB) not recognized or malformed + +/(*CRLF)(*LIMIT_MATCH=)abc/ +Failed: error 160 at offset 21: (*VERB) not recognized or malformed + # End of testinput2