Fix pcre2grep multi-line matching --only-matching option

This commit is contained in:
Petr Písař 2017-02-14 16:34:35 +01:00
parent 55e885b4cd
commit 791d16dfdc
2 changed files with 81 additions and 1 deletions

View File

@ -0,0 +1,73 @@
From dcee2708b5d37437fda9dbd07ccac6c9badd6892 Mon Sep 17 00:00:00 2001
From: ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>
Date: Fri, 10 Feb 2017 17:47:34 +0000
Subject: [PATCH] Correct fix for pcre2grep multiline with --only-matching.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This is series of two patches ported to 8.40:
commit 5be027b624bc866702808abadfe5f99360414086
Author: ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>
Date: Fri Feb 10 17:47:34 2017 +0000
Correct fix for pcre2grep multiline with --only-matching.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1678 2f5784b3-3f2a-0410-8824-cb99058d5e15
commit 8b0fdf16e57ce9a653a0a03c39f6cc061e8122e8
Author: ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>
Date: Sun Feb 12 13:28:11 2017 +0000
Fix bug in most recent fix for multiline pcre2grep.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1679 2f5784b3-3f2a-0410-8824-cb99058d5e15
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
pcregrep.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/pcregrep.c b/pcregrep.c
index fd2a676..3cd70ee 100644
--- a/pcregrep.c
+++ b/pcregrep.c
@@ -1804,11 +1804,6 @@ while (ptr < endptr)
if (line_buffered) fflush(stdout);
rc = 0; /* Had some success */
- /* If the current match ended past the end of the line (only possible
- in multiline mode), we are done with this line. */
-
- if ((unsigned int)offsets[1] > linelength) goto END_ONE_MATCH;
-
startoffset = offsets[1]; /* Restart after the match */
if (startoffset <= oldstartoffset)
{
@@ -1818,6 +1813,22 @@ while (ptr < endptr)
if (utf8)
while ((matchptr[startoffset] & 0xc0) == 0x80) startoffset++;
}
+
+ /* If the current match ended past the end of the line (only possible
+ in multiline mode), we must move on to the line in which it did end
+ before searching for more matches. */
+
+ while (startoffset > (int)linelength)
+ {
+ matchptr = ptr += linelength + endlinelength;
+ filepos += (int)(linelength + endlinelength);
+ linenumber++;
+ startoffset -= (int)(linelength + endlinelength);
+ t = end_of_line(ptr, endptr, &endlinelength);
+ linelength = t - ptr - endlinelength;
+ length = (size_t)(endptr - ptr);
+ }
+
goto ONLY_MATCHING_RESTART;
}
}
--
2.7.4

View File

@ -2,7 +2,7 @@
#%%global rcversion RC1
Name: pcre
Version: 8.40
Release: %{?rcversion:0.}1%{?rcversion:.%rcversion}%{?dist}.2
Release: %{?rcversion:0.}2%{?rcversion:.%rcversion}%{?dist}
%global myversion %{version}%{?rcversion:-%rcversion}
Summary: Perl-compatible regular expression library
Group: System Environment/Libraries
@ -34,6 +34,9 @@ Source: ftp://ftp.csx.cam.ac.uk/pub/software/programming/%{name}/%{?rcversio
Patch0: pcre-8.21-multilib.patch
# Refused by upstream, bug #675477
Patch1: pcre-8.32-refused_spelling_terminated.patch
# Fix pcre2grep multi-line matching --only-matching option, upstream bug #1848,
# in upstream after 8.40
Patch2: pcre-8.40-Correct-fix-for-pcre2grep-multiline-with-only-matchi.patch
BuildRequires: readline-devel
BuildRequires: autoconf
BuildRequires: automake
@ -123,6 +126,7 @@ Utilities demonstrating PCRE capabilities like pcregrep or pcretest.
# Get rid of rpath
%patch0 -p1
%patch1 -p1
%patch2 -p1
# Because of rpath patch
libtoolize --copy --force
autoreconf -vif
@ -219,6 +223,9 @@ make %{?_smp_mflags} check VERBOSE=yes
%{_mandir}/man1/pcretest.*
%changelog
* Tue Feb 14 2017 Petr Pisar <ppisar@redhat.com> - 8.40-2
- Fix pcre2grep multi-line matching --only-matching option (upstream bug #1848)
* Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-1.2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild