Blob Blame History Raw
From 8106259b3784b60b71427eafa40f20f191a2fe7e Mon Sep 17 00:00:00 2001
From: ph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>
Date: Wed, 11 Jan 2017 17:02:27 +0000
Subject: [PATCH] Fix pcre2test mishandling "end before start" return with
 POSIX interface.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Ported to 10.21:

commit b6c92f4b6b35ce09afcbfd71170b72d3a8bb063d
Author: ph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>
Date:   Wed Jan 11 17:02:27 2017 +0000

    Fix pcre2test mishandling "end before start" return with POSIX interface.

    git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@650 6239d852-aaf2-0410-a92c-79f79f948069

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 src/pcre2test.c       | 21 +++++++++++++++------
 testdata/testinput18  |  3 +++
 testdata/testoutput18 |  6 ++++++
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/pcre2test.c b/src/pcre2test.c
index 5bf768c..10c6a49 100644
--- a/src/pcre2test.c
+++ b/src/pcre2test.c
@@ -5814,18 +5814,27 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
       {
       if (pmatch[i].rm_so >= 0)
         {
+        PCRE2_SIZE start = pmatch[i].rm_so;
+        PCRE2_SIZE end = pmatch[i].rm_eo;
+        if (start > end)
+          {
+          start = pmatch[i].rm_eo;
+          end = pmatch[i].rm_so;
+          fprintf(outfile, "Start of matched string is beyond its end - "
+            "displaying from end to start.\n");
+          }
         fprintf(outfile, "%2d: ", (int)i);
-        PCHARSV(pp, pmatch[i].rm_so,
-          pmatch[i].rm_eo - pmatch[i].rm_so, utf, outfile);
+        PCHARSV(pp, start, end - start, utf, outfile);
         fprintf(outfile, "\n");
+
         if ((i == 0 && (dat_datctl.control & CTL_AFTERTEXT) != 0) ||
             (dat_datctl.control & CTL_ALLAFTERTEXT) != 0)
           {
           fprintf(outfile, "%2d+ ", (int)i);
-          PCHARSV(pp, pmatch[i].rm_eo, len - pmatch[i].rm_eo,
-            utf, outfile);
-          fprintf(outfile, "\n");
-          }
+          /* Note: don't use the start/end variables here because we want to
+          show the text from what is reported as the end. */
+          PCHARSV(pp, pmatch[i].rm_eo, len - pmatch[i].rm_eo, utf, outfile);
+          fprintf(outfile, "\n"); }
         }
       }
     }
diff --git a/testdata/testinput18 b/testdata/testinput18
index c75b842..09fea7d 100644
--- a/testdata/testinput18
+++ b/testdata/testinput18
@@ -98,4 +98,7 @@
 
 /\[A]{1000000}**/expand,regerror_buffsize=32
 
+/(?=(a\K))/
+    a
+     
 # End of testdata/testinput18
diff --git a/testdata/testoutput18 b/testdata/testoutput18
index 0a5ffff..2c457c1 100644
--- a/testdata/testoutput18
+++ b/testdata/testoutput18
@@ -150,4 +150,10 @@ Failed: POSIX code 4: ? * + invalid at offset 100000
 /\[A]{1000000}**/expand,regerror_buffsize=32
 Failed: POSIX code 4: ? * + invalid at offset 1000001
 
+/(?=(a\K))/
+    a
+Start of matched string is beyond its end - displaying from end to start.
+ 0: a
+ 1: a
+     
 # End of testdata/testinput18
-- 
2.7.4