Blame SOURCES/pcre-8.32-Fix-workspace-overflow-for-ACCEPT-with-deeply-nested.patch

08805a
From 01611089a2be24b740e67d5fac8d7b44b2330302 Mon Sep 17 00:00:00 2001
08805a
From: ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>
08805a
Date: Wed, 10 Feb 2016 19:13:17 +0000
08805a
Subject: [PATCH] Fix workspace overflow for (*ACCEPT) with deeply nested
08805a
 parentheses.
08805a
MIME-Version: 1.0
08805a
Content-Type: text/plain; charset=UTF-8
08805a
Content-Transfer-Encoding: 8bit
08805a
08805a
Ported to 8.32:
08805a
08805a
commit 943a5105b9fe2842851003f692c7077a6cdbeefe
08805a
Author: ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>
08805a
Date:   Wed Feb 10 19:13:17 2016 +0000
08805a
08805a
    Fix workspace overflow for (*ACCEPT) with deeply nested parentheses.
08805a
08805a
    git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1631 2f5784b3-3f2a-0410-8824-cb99058d5e15
08805a
08805a
Signed-off-by: Petr Písař <ppisar@redhat.com>
08805a
---
08805a
 pcre_compile.c           | 21 ++++++++++++++++++---
08805a
 pcre_internal.h          |  2 +-
08805a
 pcreposix.c              |  3 ++-
08805a
 testdata/testinput11     |  2 ++
08805a
 testdata/testoutput11-16 |  3 +++
08805a
 testdata/testoutput11-32 |  3 +++
08805a
 testdata/testoutput11-8  |  3 +++
08805a
 7 files changed, 32 insertions(+), 5 deletions(-)
08805a
08805a
diff --git a/pcre_compile.c b/pcre_compile.c
08805a
index 8eb4b0f..746dc70 100644
08805a
--- a/pcre_compile.c
08805a
+++ b/pcre_compile.c
08805a
@@ -508,6 +508,7 @@ static const char error_texts[] =
08805a
   "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"
08805a
   "character value in \\u.... sequence is too large\0"
08805a
   "invalid UTF-32 string\0"
08805a
+  "regular expression is too complicated\0"
08805a
   ;
08805a
 
08805a
 /* Table to identify digits and hex digits. This is used when compiling
08805a
@@ -3881,7 +3882,8 @@ for (;; ptr++)
08805a
     if (code > cd->start_workspace + cd->workspace_size -
08805a
         WORK_SIZE_SAFETY_MARGIN)                       /* Check for overrun */
08805a
       {
08805a
-      *errorcodeptr = ERR52;
08805a
+      *errorcodeptr = (code >= cd->start_workspace + cd->workspace_size)?
08805a
+        ERR52 : ERR87;
08805a
       goto FAILED;
08805a
       }
08805a
 
08805a
@@ -5701,8 +5703,21 @@ for (;; ptr++)
08805a
             cd->had_accept = TRUE;
08805a
             for (oc = cd->open_caps; oc != NULL; oc = oc->next)
08805a
               {
08805a
-              *code++ = OP_CLOSE;
08805a
-              PUT2INC(code, 0, oc->number);
08805a
+              if (lengthptr != NULL)
08805a
+                {
08805a
+#ifdef COMPILE_PCRE8
08805a
+                *lengthptr += 1 + IMM2_SIZE;
08805a
+#elif defined COMPILE_PCRE16
08805a
+                *lengthptr += 2 + IMM2_SIZE;
08805a
+#elif defined COMPILE_PCRE32
08805a
+                *lengthptr += 4 + IMM2_SIZE;
08805a
+#endif
08805a
+                }
08805a
+              else
08805a
+                {
08805a
+                *code++ = OP_CLOSE;
08805a
+                PUT2INC(code, 0, oc->number);
08805a
+                }
08805a
               }
08805a
             setverb = *code++ =
08805a
               (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
08805a
diff --git a/pcre_internal.h b/pcre_internal.h
08805a
index 536b3d8..157de08 100644
08805a
--- a/pcre_internal.h
08805a
+++ b/pcre_internal.h
08805a
@@ -2270,7 +2270,7 @@ enum { ERR0,  ERR1,  ERR2,  ERR3,  ERR4,  ERR5,  ERR6,  ERR7,  ERR8,  ERR9,
08805a
        ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49,
08805a
        ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59,
08805a
        ERR60, ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69,
08805a
-       ERR70, ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERRCOUNT };
08805a
+       ERR70, ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERR87, ERRCOUNT };
08805a
 
08805a
 /* JIT compiling modes. The function list is indexed by them. */
08805a
 enum { JIT_COMPILE, JIT_PARTIAL_SOFT_COMPILE, JIT_PARTIAL_HARD_COMPILE,
08805a
diff --git a/pcreposix.c b/pcreposix.c
08805a
index 15195c0..700676c 100644
08805a
--- a/pcreposix.c
08805a
+++ b/pcreposix.c
08805a
@@ -162,7 +162,8 @@ static const int eint[] = {
08805a
   /* 75 */
08805a
   REG_BADPAT,  /* overlong MARK name */
08805a
   REG_BADPAT,  /* character value in \u.... sequence is too large */
08805a
-  REG_BADPAT   /* invalid UTF-32 string (should not occur) */
08805a
+  REG_BADPAT,  /* invalid UTF-32 string (should not occur) */
08805a
+  REG_BADPAT   /* pattern too complicated */
08805a
 };
08805a
 
08805a
 /* Table of texts corresponding to POSIX error codes */
08805a
diff --git a/testdata/testinput11 b/testdata/testinput11
08805a
index 7e8e542..014c722 100644
08805a
--- a/testdata/testinput11
08805a
+++ b/testdata/testinput11
08805a
@@ -134,4 +134,6 @@ is required for these tests. --/
08805a
 
08805a
 /(((a\2)|(a*)\g<-1>))*a?/B
08805a
 
08805a
+/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/
08805a
+
08805a
 /-- End of testinput11 --/
08805a
diff --git a/testdata/testoutput11-16 b/testdata/testoutput11-16
08805a
index 3cb3049..6ae9e2f 100644
08805a
--- a/testdata/testoutput11-16
08805a
+++ b/testdata/testoutput11-16
08805a
@@ -734,4 +734,7 @@ Memory allocation (code space): 14
08805a
  41     End
08805a
 ------------------------------------------------------------------
08805a
 
08805a
+/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/
08805a
+Failed: regular expression is too complicated at offset 490
08805a
+
08805a
 /-- End of testinput11 --/
08805a
diff --git a/testdata/testoutput11-32 b/testdata/testoutput11-32
08805a
index 10dee82..124e3d1 100644
08805a
--- a/testdata/testoutput11-32
08805a
+++ b/testdata/testoutput11-32
08805a
@@ -734,4 +734,7 @@ Memory allocation (code space): 28
08805a
  41     End
08805a
 ------------------------------------------------------------------
08805a
 
08805a
+/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/
08805a
+Failed: missing ) at offset 509
08805a
+
08805a
 /-- End of testinput11 --/
08805a
diff --git a/testdata/testoutput11-8 b/testdata/testoutput11-8
08805a
index a1bd60a..36f6e64 100644
08805a
--- a/testdata/testoutput11-8
08805a
+++ b/testdata/testoutput11-8
08805a
@@ -734,4 +734,7 @@ Memory allocation (code space): 10
08805a
  60     End
08805a
 ------------------------------------------------------------------
08805a
 
08805a
+/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/
08805a
+Failed: missing ) at offset 509
08805a
+
08805a
 /-- End of testinput11 --/
08805a
-- 
08805a
2.5.5
08805a