Blob Blame History Raw
From cfece5a321516df752f6f70e497c7b92db977024 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Tue, 9 Jun 2015 16:46:52 +0000
Subject: [PATCH] Fix overflow when ovector has size 1.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Upstream commit ported to 8.37:

commit b5c4f0f2bef3a0dff74e4de806b8b5280bb666c0
Author: ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>
Date:   Tue Jun 9 16:46:52 2015 +0000

    Fix overflow when ovector has size 1.

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 pcre_exec.c          | 3 ++-
 testdata/testinput2  | 3 +++
 testdata/testoutput2 | 4 ++++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/pcre_exec.c b/pcre_exec.c
index c021fe1..24b23ca 100644
--- a/pcre_exec.c
+++ b/pcre_exec.c
@@ -6685,7 +6685,8 @@ if (md->offset_vector != NULL)
   register int *iend = iptr - re->top_bracket;
   if (iend < md->offset_vector + 2) iend = md->offset_vector + 2;
   while (--iptr >= iend) *iptr = -1;
-  md->offset_vector[0] = md->offset_vector[1] = -1;
+  if (offsetcount > 0) md->offset_vector[0] = -1;
+  if (offsetcount > 1) md->offset_vector[1] = -1;
   }
 
 /* Set up the first character to match, if available. The first_char value is
diff --git a/testdata/testinput2 b/testdata/testinput2
index c5ac208..32bf612 100644
--- a/testdata/testinput2
+++ b/testdata/testinput2
@@ -4164,4 +4164,7 @@ backtracking verbs. --/
 
 /a[[:punct:]b]/BZ
 
+//
+\O1
+
 /-- End of testinput2 --/
diff --git a/testdata/testoutput2 b/testdata/testoutput2
index 8801d0c..f41ca63 100644
--- a/testdata/testoutput2
+++ b/testdata/testoutput2
@@ -14443,4 +14443,8 @@ Failed: unmatched parentheses at offset 23
         End
 ------------------------------------------------------------------
 
+//
+\O1
+Matched, but too many substrings
+
 /-- End of testinput2 --/
-- 
2.4.3