pcre2/pcre2-10.21-Detect-unmatched-closing-parentheses-in-the-pre-scan.patch
2016-02-11 09:07:37 +01:00

123 lines
4.2 KiB
Diff

From 3c570a60f7386ec026ef5dcafd54200d85826604 Mon Sep 17 00:00:00 2001
From: ph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>
Date: Tue, 2 Feb 2016 17:22:55 +0000
Subject: [PATCH] Detect unmatched closing parentheses in the pre-scan to avoid
giving incorrect error messages.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@484 6239d852-aaf2-0410-a92c-79f79f948069
Petr Písař: Ported to 10.21.
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
src/pcre2_compile.c | 43 +++++++++++++++++++++----------------------
testdata/testinput2 | 2 ++
testdata/testoutput2 | 3 +++
3 files changed, 26 insertions(+), 22 deletions(-)
diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c
index d852837..e33d620 100644
--- a/src/pcre2_compile.c
+++ b/src/pcre2_compile.c
@@ -3377,27 +3377,24 @@ for (; ptr < cb->end_pattern; ptr++)
if ((options & PCRE2_NO_AUTO_CAPTURE) == 0) cb->bracount++;
}
- /* (*something) - just skip to closing ket unless PCRE2_ALT_VERBNAMES is
- set, in which case we have to process escapes in the string after the
- name. */
+ /* (*something) - skip over a name, and then just skip to closing ket
+ unless PCRE2_ALT_VERBNAMES is set, in which case we have to process
+ escapes in the string after a verb name terminated by a colon. */
else
{
ptr += 2;
while (MAX_255(*ptr) && (cb->ctypes[*ptr] & ctype_word) != 0) ptr++;
- if (*ptr == CHAR_COLON)
+ if (*ptr == CHAR_COLON && (options & PCRE2_ALT_VERBNAMES) != 0)
{
ptr++;
- if ((options & PCRE2_ALT_VERBNAMES) != 0)
- {
- if (process_verb_name(&ptr, NULL, &errorcode, options, utf, cb) < 0)
- goto FAILED;
- }
- else
- {
- while (ptr < cb->end_pattern && *ptr != CHAR_RIGHT_PARENTHESIS)
- ptr++;
- }
+ if (process_verb_name(&ptr, NULL, &errorcode, options, utf, cb) < 0)
+ goto FAILED;
+ }
+ else
+ {
+ while (ptr < cb->end_pattern && *ptr != CHAR_RIGHT_PARENTHESIS)
+ ptr++;
}
nest_depth--;
}
@@ -3748,7 +3745,12 @@ for (; ptr < cb->end_pattern; ptr++)
if (top_nest == (nest_save *)(cb->start_workspace)) top_nest = NULL;
else top_nest--;
}
- if (nest_depth > 0) nest_depth--; /* Can be 0 for unmatched ) */
+ if (nest_depth == 0) /* Unmatched closing parenthesis */
+ {
+ errorcode = ERR22;
+ goto FAILED;
+ }
+ nest_depth--;
break;
}
}
@@ -8704,14 +8706,11 @@ if (cb.had_accept)
reqcuflags = REQ_NONE;
}
-/* If we have not reached end of pattern after a successful compile, there's an
-excess bracket. Fill in the final opcode and check for disastrous overflow.
-If no overflow, but the estimated length exceeds the really used length, adjust
-the value of re->blocksize, and if valgrind support is configured, mark the
-extra allocated memory as unaddressable, so that any out-of-bound reads can be
-detected. */
+/* Fill in the final opcode and check for disastrous overflow. If no overflow,
+but the estimated length exceeds the really used length, adjust the value of
+re->blocksize, and if valgrind support is configured, mark the extra allocated
+memory as unaddressable, so that any out-of-bound reads can be detected. */
-if (errorcode == 0 && ptr < cb.end_pattern) errorcode = ERR22;
*code++ = OP_END;
usedlength = code - codestart;
if (usedlength > length) errorcode = ERR23; else
diff --git a/testdata/testinput2 b/testdata/testinput2
index 071cca1..86c149d 100644
--- a/testdata/testinput2
+++ b/testdata/testinput2
@@ -4800,4 +4800,6 @@ a)"xI
/28 2a 4d 41 52 4b 3a 41 00 62 29/mark,hex,alt_verbnames
abc
+/(?J)(?'a'))(?'a')/
+
# End of testinput2
diff --git a/testdata/testoutput2 b/testdata/testoutput2
index 7178410..87c7204 100644
--- a/testdata/testoutput2
+++ b/testdata/testoutput2
@@ -15158,4 +15158,7 @@ MK: A\x00b
0:
MK: A\x00b
+/(?J)(?'a'))(?'a')/
+Failed: error 122 at offset 10: unmatched closing parenthesis
+
# End of testinput2
--
2.5.0