09a9293
From 4c90a8bb06e8bed4b62e15b78b461edb0e606df5 Mon Sep 17 00:00:00 2001
09a9293
From: Peter Lemenkov <lemenkov@gmail.com>
09a9293
Date: Mon, 19 Apr 2010 13:45:41 +0400
09a9293
Subject: [PATCH 7/7] Fix check for compile workspace overflow
09a9293
09a9293
Patch from:
09a9293
http://vcs.pcre.org/viewvc/code/trunk/pcre_compile.c?r1=504&r2=505&view=patch
09a9293
09a9293
Test case:
09a9293
N = 819, re:compile([lists:duplicate(N, $(), lists:duplicate(N, $))]).
09a9293
09a9293
Compiling large regular expressions could overflow the workspace
09a9293
buffer. Modify the test to check for a value smaller than the buffer
09a9293
size.
09a9293
---
09a9293
 erts/emulator/pcre/pcre_compile.c |    9 +++++++--
09a9293
 1 files changed, 7 insertions(+), 2 deletions(-)
09a9293
09a9293
diff --git a/erts/emulator/pcre/pcre_compile.c b/erts/emulator/pcre/pcre_compile.c
09a9293
index 5d2be9a..08ce2b0 100644
09a9293
--- a/erts/emulator/pcre/pcre_compile.c
09a9293
+++ b/erts/emulator/pcre/pcre_compile.c
09a9293
@@ -91,6 +91,11 @@ is 4 there is plenty of room. */
09a9293
 
09a9293
 #define COMPILE_WORK_SIZE (4096)
09a9293
 
09a9293
+/* The overrun tests check for a slightly smaller size so that they detect the
09a9293
+overrun before it actually does run off the end of the data block. */
09a9293
+
09a9293
+#define WORK_SIZE_CHECK (COMPILE_WORK_SIZE - 100)
09a9293
+
09a9293
 
09a9293
 /* Table for handling escaped characters in the range '0'-'z'. Positive returns
09a9293
 are simple data values; negative values are for special things like \d and so
09a9293
@@ -2444,7 +2449,7 @@ for (;; ptr++)
09a9293
 #ifdef DEBUG
09a9293
     if (code > cd->hwm) cd->hwm = code;                 /* High water info */
09a9293
 #endif
09a9293
-    if (code > cd->start_workspace + COMPILE_WORK_SIZE) /* Check for overrun */
09a9293
+    if (code > cd->start_workspace + WORK_SIZE_CHECK)   /* Check for overrun */
09a9293
       {
09a9293
       *errorcodeptr = ERR52;
09a9293
       goto FAILED;
09a9293
@@ -2493,7 +2498,7 @@ for (;; ptr++)
09a9293
   /* In the real compile phase, just check the workspace used by the forward
09a9293
   reference list. */
09a9293
 
09a9293
-  else if (cd->hwm > cd->start_workspace + COMPILE_WORK_SIZE)
09a9293
+  else if (cd->hwm > cd->start_workspace + WORK_SIZE_CHECK)
09a9293
     {
09a9293
     *errorcodeptr = ERR52;
09a9293
     goto FAILED;
09a9293
-- 
09a9293
1.6.6.1
09a9293