mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #9669: Protect re against infinite loops on zero-width matching in
non-greedy repeat. Patch by Matthew Barnett.
This commit is contained in:
commit
b0c75a7dec
3 changed files with 19 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue