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