Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard against out-of-bounds memory access when parsing LIMIT_HEAP et al #463

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/pcre2_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -10551,12 +10551,12 @@ if ((options & PCRE2_LITERAL) == 0)
ptr += pp;
goto HAD_EARLY_ERROR;
}
while (IS_DIGIT(ptr[pp]))
while (pp < patlen && IS_DIGIT(ptr[pp]))
{
if (c > UINT32_MAX / 10 - 1) break; /* Integer overflow */
c = c*10 + (ptr[pp++] - CHAR_0);
}
if (ptr[pp++] != CHAR_RIGHT_PARENTHESIS)
if (pp >= patlen || ptr[pp] != CHAR_RIGHT_PARENTHESIS)
{
errorcode = ERR60;
ptr += pp;
Expand All @@ -10565,14 +10565,15 @@ if ((options & PCRE2_LITERAL) == 0)
if (p->type == PSO_LIMH) limit_heap = c;
else if (p->type == PSO_LIMM) limit_match = c;
else limit_depth = c;
skipatstart += pp - skipatstart;
skipatstart = ++pp;
break;
}
break; /* Out of the table scan loop */
}
}
if (i >= sizeof(pso_list)/sizeof(pso)) break; /* Out of pso loop */
}
PCRE2_ASSERT(skipatstart <= patlen);
}

/* End of pattern-start options; advance to start of real regex. */
Expand Down
4 changes: 2 additions & 2 deletions testdata/testoutput15
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ Minimum depth limit = 10
3: ee

/(*LIMIT_MATCH=12bc)abc/
Failed: error 160 at offset 17: (*VERB) not recognized or malformed
Failed: error 160 at offset 16: (*VERB) not recognized or malformed
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more logical now: the first bad character in the LIMIT_MATCH construct is at offset 16, not offset 17.


/(*LIMIT_MATCH=4294967290)abc/
Failed: error 160 at offset 24: (*VERB) not recognized or malformed
Failed: error 160 at offset 23: (*VERB) not recognized or malformed

/(*LIMIT_DEPTH=4294967280)abc/I
Capture group count = 0
Expand Down
Loading