summaryrefslogtreecommitdiffstats
path: root/Modules/_sre.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-16 19:25:40 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-16 19:25:40 (GMT)
commite924ddb23e4276b601cdc13d2988e501123f85fb (patch)
treea9902132a3f6c364396ce92e6bd273ca33a52765 /Modules/_sre.c
parent0e6b7b5cd2f1bae9bdceac4d2bedfd6674250ac1 (diff)
parentb0c75a7dec2ae9d514ac8df63a4822215e486e1f (diff)
downloadcpython-e924ddb23e4276b601cdc13d2988e501123f85fb.zip
cpython-e924ddb23e4276b601cdc13d2988e501123f85fb.tar.gz
cpython-e924ddb23e4276b601cdc13d2988e501123f85fb.tar.bz2
Issue #9669: Protect re against infinite loops on zero-width matching in
non-greedy repeat. Patch by Matthew Barnett.
Diffstat (limited to 'Modules/_sre.c')
-rw-r--r--Modules/_sre.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index f2d8a37..d8e2418 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -1272,13 +1272,18 @@ entrance:
LASTMARK_RESTORE();
- if (ctx->count >= ctx->u.rep->pattern[2]
- && ctx->u.rep->pattern[2] != SRE_MAXREPEAT)
+ if ((ctx->count >= ctx->u.rep->pattern[2]
+ && ctx->u.rep->pattern[2] != SRE_MAXREPEAT) ||
+ state->ptr == ctx->u.rep->last_ptr)
RETURN_FAILURE;
ctx->u.rep->count = ctx->count;
+ /* zero-width match protection */
+ DATA_PUSH(&ctx->u.rep->last_ptr);
+ ctx->u.rep->last_ptr = state->ptr;
DO_JUMP(JUMP_MIN_UNTIL_3,jump_min_until_3,
ctx->u.rep->pattern+3);
+ DATA_POP(&ctx->u.rep->last_ptr);
if (ret) {
RETURN_ON_ERROR(ret);
RETURN_SUCCESS;