[Pcre-svn] [662] code/trunk: Fix previously broken fix for …

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [662] code/trunk: Fix previously broken fix for pcre2grep with -Mo matching strings that cross
Revision: 662
          http://www.exim.org/viewvc/pcre2?view=rev&revision=662
Author:   ph10
Date:     2017-02-10 17:39:29 +0000 (Fri, 10 Feb 2017)
Log Message:
-----------
Fix previously broken fix for pcre2grep with -Mo matching strings that cross 
line boundaries.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/RunGrepTest
    code/trunk/src/pcre2grep.c
    code/trunk/testdata/grepoutput


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2017-02-10 16:42:14 UTC (rev 661)
+++ code/trunk/ChangeLog    2017-02-10 17:39:29 UTC (rev 662)
@@ -352,7 +352,12 @@
 complicated that this optimization probably isn't worth it.) This fixes 
 oss-fuzz issue 557.


+55. Issue 32 for 10.22 below was not correctly fixed. If pcre2grep in multiline
+mode with --only-matching matched several lines, it restarted scanning at the
+next line instead of moving on to the end of the matched string, which can be
+several lines after the start.

+
Version 10.22 29-July-2016
--------------------------


Modified: code/trunk/RunGrepTest
===================================================================
--- code/trunk/RunGrepTest    2017-02-10 16:42:14 UTC (rev 661)
+++ code/trunk/RunGrepTest    2017-02-10 17:39:29 UTC (rev 662)
@@ -593,6 +593,11 @@
 (cd $srcdir; $valgrind $vjs $pcre2grep -tL 'the' testdata/grepinput*) >>testtrygrep
 echo "RC=$?" >>testtrygrep


+echo "---------------------------- Test 119 -----------------------------" >>testtrygrep
+printf "123\n456\n789\n---abc\ndef\nxyz\n---\n" >testNinputgrep
+(cd $srcdir; $valgrind $vjs $pcre2grep -Mo '(\n|[^-])*---' testNinputgrep) >>testtrygrep
+echo "RC=$?" >>testtrygrep
+
# Now compare the results.

$cf $srcdir/testdata/grepoutput testtrygrep

Modified: code/trunk/src/pcre2grep.c
===================================================================
--- code/trunk/src/pcre2grep.c    2017-02-10 16:42:14 UTC (rev 661)
+++ code/trunk/src/pcre2grep.c    2017-02-10 17:39:29 UTC (rev 662)
@@ -2285,11 +2285,6 @@
         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 (offsets[1] > linelength) goto END_ONE_MATCH;
-
         /* If the pattern contained a lookbehind that included \K, it is
         possible that the end of the match might be at or before the actual
         starting offset we have just used. In this case, start one character
@@ -2301,9 +2296,23 @@
           {
           if (startoffset >= length) goto END_ONE_MATCH;  /* Were at end */
           startoffset = oldstartoffset + 1;
-          if (utf)
-            while ((matchptr[startoffset] & 0xc0) == 0x80) startoffset++;
+          if (utf) 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 > 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;
+          }
+
         goto ONLY_MATCHING_RESTART;
         }
       }


Modified: code/trunk/testdata/grepoutput
===================================================================
(Binary files differ)