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

gh17730: regcomp overflow/underflow #17744

Merged
merged 2 commits into from
Apr 25, 2020
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
8 changes: 6 additions & 2 deletions regcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,8 @@ S_scan_commit(pTHX_ const RExC_state_t *pRExC_state, scan_data_t *data,
? OPTIMIZE_INFTY
: (l
? data->last_start_max
/* temporary underflow guard for 5.32 */
: data->pos_delta < 0 ? OPTIMIZE_INFTY
: (data->pos_delta > OPTIMIZE_INFTY - data->pos_min
? OPTIMIZE_INFTY
: data->pos_min + data->pos_delta));
Expand Down Expand Up @@ -5306,8 +5308,10 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
offset, later match for variable offset. */
if (data->last_end == -1) { /* Update the start info. */
data->last_start_min = data->pos_min;
data->last_start_max = is_inf
? OPTIMIZE_INFTY : data->pos_min + data->pos_delta;
data->last_start_max =
is_inf ? OPTIMIZE_INFTY
: (data->pos_delta > OPTIMIZE_INFTY - data->pos_min)
? OPTIMIZE_INFTY : data->pos_min + data->pos_delta;
}
sv_catpvn(data->last_found, STRING(scan), bytelen);
if (UTF)
Expand Down
9 changes: 8 additions & 1 deletion t/re/pat.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ BEGIN {

skip_all_without_unicode_tables();

plan tests => 1019; # Update this when adding/deleting tests.
plan tests => 1020; # Update this when adding/deleting tests.

run_tests() unless caller;

Expand Down Expand Up @@ -2264,6 +2264,13 @@ SKIP:
'ok', {}, "gh16947: test fix doesn't break SUSPEND");
}

# gh17730: should not crash
{
fresh_perl_is(q{
"q00" =~ m{(((*ACCEPT)0)*00)?0(?1)}; print "ok"
}, 'ok', {}, 'gh17730: should not crash');
}

} # End of sub run_tests

1;
Expand Down