summaryrefslogtreecommitdiff
path: root/pcre_exec.c
diff options
context:
space:
mode:
authorph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2011-07-28 18:59:40 +0000
committerph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2011-07-28 18:59:40 +0000
commit5eb8d51bae2ddf98313629134e88a389fe319605 (patch)
tree0d30190424c6c64c165f3c0d8de9277ac03e2e70 /pcre_exec.c
parent7c4c354abaae9c3d29cb7cd47be7bcdee4078bbe (diff)
downloadpcre-5eb8d51bae2ddf98313629134e88a389fe319605.tar.gz
Avoid false positive for infinite recursion by not checking conditionals at
compile time, but add tests at runtime that also catch infinite mutual recursion. git-svn-id: svn://vcs.exim.org/pcre/code/trunk@642 2f5784b3-3f2a-0410-8824-cb99058d5e15
Diffstat (limited to 'pcre_exec.c')
-rw-r--r--pcre_exec.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/pcre_exec.c b/pcre_exec.c
index 7e07fc2..ffff54c 100644
--- a/pcre_exec.c
+++ b/pcre_exec.c
@@ -1501,12 +1501,25 @@ for (;;)
case OP_RECURSE:
{
+ recursion_info *ri;
+ int recno;
+
callpat = md->start_code + GET(ecode, 1);
- new_recursive.group_num = (callpat == md->start_code)? 0 :
- GET2(callpat, 1 + LINK_SIZE);
+ recno = (callpat == md->start_code)? 0 :
+ GET2(callpat, 1 + LINK_SIZE);
+
+ /* Check for repeating a recursion without advancing the subject pointer.
+ This should catch convoluted mutual recursions. (Some simple cases are
+ caught at compile time.) */
+
+ for (ri = md->recursive; ri != NULL; ri = ri->prevrec)
+ if (recno == ri->group_num && eptr == ri->subject_position)
+ RRETURN(PCRE_ERROR_RECURSELOOP);
/* Add to "recursing stack" */
+ new_recursive.group_num = recno;
+ new_recursive.subject_position = eptr;
new_recursive.prevrec = md->recursive;
md->recursive = &new_recursive;