Blame otp-0006-Fix-check-for-compile-workspace-overflow.patch

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