summaryrefslogtreecommitdiffstats
path: root/Modules/_sre.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-16 19:23:53 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-16 19:23:53 (GMT)
commitfa4681691591429466d18e21d7640e3703ab7f28 (patch)
tree91ef35df8dbbfcf6cab1a0ce75e4495dcdf2f826 /Modules/_sre.c
parent70ca0210e8958d2665541ddd38fce2965075674e (diff)
downloadcpython-fa4681691591429466d18e21d7640e3703ab7f28.zip
cpython-fa4681691591429466d18e21d7640e3703ab7f28.tar.gz
cpython-fa4681691591429466d18e21d7640e3703ab7f28.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 4421eae..e76144d 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -1295,13 +1295,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;