diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rwxr-xr-x | RunGrepTest | 5 | ||||
-rw-r--r-- | src/pcre2grep.c | 23 | ||||
-rw-r--r-- | testdata/grepoutput | 10 |
4 files changed, 36 insertions, 7 deletions
@@ -352,6 +352,11 @@ group whose number is greater than 128. (In that case, the pattern is so 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 -------------------------- diff --git a/RunGrepTest b/RunGrepTest index afe3c1e..1ecb2be 100755 --- a/RunGrepTest +++ b/RunGrepTest @@ -593,6 +593,11 @@ echo "---------------------------- Test 118 -----------------------------" >>tes (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 diff --git a/src/pcre2grep.c b/src/pcre2grep.c index dcca69c..6fa3b04 100644 --- a/src/pcre2grep.c +++ b/src/pcre2grep.c @@ -2285,11 +2285,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 (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 @@ while (ptr < endptr) { 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; } } diff --git a/testdata/grepoutput b/testdata/grepoutput index ee9a9eb..87fe428 100644 --- a/testdata/grepoutput +++ b/testdata/grepoutput @@ -819,3 +819,13 @@ RC=0 testdata/grepinput3 testdata/grepinput8 RC=0 +---------------------------- Test 119 ----------------------------- +123 +456 +789 +--- +abc +def +xyz +--- +RC=0 |