Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 18c2aa2

Browse files
author
Fredrik Lundh
committed
+ if USE_STACKCHECK is defined, use PyOS_CheckStack to look
for excessive recursion.
1 parent aa39a7e commit 18c2aa2

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Modules/_sre.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ char copyright[] = " SRE 0.9.8 Copyright (c) 1997-2000 by Secret Labs AB ";
5858
/* optional features */
5959

6060
/* prevent run-away recursion (bad patterns on long strings) */
61+
#if !defined(USE_STACKCHECK)
6162
#define USE_RECURSION_LIMIT 10000
63+
#endif
6264

6365
/* enables fast searching */
6466
#define USE_FAST_SEARCH
@@ -527,6 +529,11 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
527529

528530
TRACE(("%8d: enter %d\n", PTR(ptr), level));
529531

532+
#if defined(USE_STACKCHECK)
533+
if (level % 10 == 0 && PyOS_CheckStack()) {
534+
return SRE_ERROR_RECURSION_LIMIT;
535+
#endif
536+
530537
#if defined(USE_RECURSION_LIMIT)
531538
if (level > USE_RECURSION_LIMIT)
532539
return SRE_ERROR_RECURSION_LIMIT;

0 commit comments

Comments
 (0)