Report unmatched closing parantheses properly

This commit is contained in:
Petr Písař 2016-02-11 09:07:37 +01:00
parent 3342aef682
commit 92a174608e
2 changed files with 129 additions and 1 deletions

View File

@ -0,0 +1,122 @@
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

View File

@ -2,7 +2,7 @@
#%%global rcversion RC1 #%%global rcversion RC1
Name: pcre2 Name: pcre2
Version: 10.21 Version: 10.21
Release: %{?rcversion:0.}1%{?rcversion:.%rcversion}%{?dist}.1 Release: %{?rcversion:0.}2%{?rcversion:.%rcversion}%{?dist}
%global myversion %{version}%{?rcversion:-%rcversion} %global myversion %{version}%{?rcversion:-%rcversion}
Summary: Perl-compatible regular expression library Summary: Perl-compatible regular expression library
Group: System Environment/Libraries Group: System Environment/Libraries
@ -20,6 +20,8 @@ URL: http://www.pcre.org/
Source: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/%{?rcversion:Testing/}%{name}-%{myversion}.tar.bz2 Source: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/%{?rcversion:Testing/}%{name}-%{myversion}.tar.bz2
# Do no set RPATH if libdir is not /usr/lib # Do no set RPATH if libdir is not /usr/lib
Patch0: pcre2-10.10-Fix-multilib.patch Patch0: pcre2-10.10-Fix-multilib.patch
# Report unmatched closing parantheses properly, in upstream after 10.21
Patch1: pcre2-10.21-Detect-unmatched-closing-parentheses-in-the-pre-scan.patch
# New libtool to get rid of RPATH and to use distribution autotools # New libtool to get rid of RPATH and to use distribution autotools
BuildRequires: autoconf BuildRequires: autoconf
@ -80,6 +82,7 @@ Utilities demonstrating PCRE2 capabilities like pcre2grep or pcre2test.
%prep %prep
%setup -q -n %{name}-%{myversion} %setup -q -n %{name}-%{myversion}
%patch0 -p1 %patch0 -p1
%patch1 -p1
# Because of multilib patch # Because of multilib patch
libtoolize --copy --force libtoolize --copy --force
autoreconf -vif autoreconf -vif
@ -159,6 +162,9 @@ make %{?_smp_mflags} check VERBOSE=yes
%{_mandir}/man1/pcre2test.* %{_mandir}/man1/pcre2test.*
%changelog %changelog
* Thu Feb 11 2016 Petr Pisar <ppisar@redhat.com> - 10.21-2
- Report unmatched closing parantheses properly
* Thu Feb 04 2016 Fedora Release Engineering <releng@fedoraproject.org> - 10.21-1.1 * Thu Feb 04 2016 Fedora Release Engineering <releng@fedoraproject.org> - 10.21-1.1
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild - Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild