Revision: 531
http://vcs.pcre.org/viewvc?view=rev&revision=531
Author: ph10
Date: 2010-06-01 14:53:26 +0100 (Tue, 01 Jun 2010)
Log Message:
-----------
Check for running out of memory when using heap for recursion.
Modified Paths:
--------------
code/trunk/ChangeLog
code/trunk/doc/pcreapi.3
code/trunk/pcre_exec.c
Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog 2010-06-01 13:42:06 UTC (rev 530)
+++ code/trunk/ChangeLog 2010-06-01 13:53:26 UTC (rev 531)
@@ -67,6 +67,9 @@
17. Added a lot of (int) casts to avoid compiler warnings in systems where
size_t is 64-bit.
+
+18. Added a check for running out of memory when PCRE is compiled with
+ --disable-stack-for-recursion.
Modified: code/trunk/doc/pcreapi.3
===================================================================
--- code/trunk/doc/pcreapi.3 2010-06-01 13:42:06 UTC (rev 530)
+++ code/trunk/doc/pcreapi.3 2010-06-01 13:53:26 UTC (rev 531)
@@ -1643,6 +1643,10 @@
gets a block of memory at the start of matching to use for this purpose. If the
call via \fBpcre_malloc()\fP fails, this error is given. The memory is
automatically freed at the end of matching.
+.P
+This error is also given if \fBpcre_stack_malloc()\fP fails in
+\fBpcre_exec()\fP. This can happen only when PCRE has been compiled with
+\fB--disable-stack-for-recursion\fP.
.sp
PCRE_ERROR_NOSUBSTRING (-7)
.sp
@@ -2127,6 +2131,6 @@
.rs
.sp
.nf
-Last updated: 26 May 2010
+Last updated: 01 June 2010
Copyright (c) 1997-2010 University of Cambridge.
.fi
Modified: code/trunk/pcre_exec.c
===================================================================
--- code/trunk/pcre_exec.c 2010-06-01 13:42:06 UTC (rev 530)
+++ code/trunk/pcre_exec.c 2010-06-01 13:53:26 UTC (rev 531)
@@ -295,6 +295,7 @@
#define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
{\
heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
+ if (heapframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\
frame->Xwhere = rw; \
newframe->Xeptr = ra;\
newframe->Xecode = rb;\
@@ -488,6 +489,7 @@
#ifdef NO_RECURSE
heapframe *frame = (pcre_stack_malloc)(sizeof(heapframe));
+if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
frame->Xprevframe = NULL; /* Marks the top level */
/* Copy in the original argument variables */
@@ -794,7 +796,7 @@
save_capture_last = md->capture_last;
DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
- md->offset_vector[md->offset_end - number] =
+ md->offset_vector[md->offset_end - number] =
(int)(eptr - md->start_subject);
flags = (op == OP_SCBRA)? match_cbegroup : 0;