Skip to content

Commit bbf8362

Browse files
committed
regexec.c - add assert and test for savestack overflow in Issue #20826.
We have a bug where we can overflow the save-stack. This tests for it in a TODO test. The next patch will fix it. Note the test will only fail in debugging as it requires the assert() to be compiled in.
1 parent 0a73ee9 commit bbf8362

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

regexec.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ S_regcppush(pTHX_ const regexp *rex, I32 parenfloor, U32 maxopenparen _pDEPTH)
263263
);
264264

265265
SSCHECK(total_elems + REGCP_FRAME_ELEMS);
266+
assert((IV)PL_savestack_max > (IV)(total_elems + REGCP_FRAME_ELEMS));
266267

267268
/* memcpy the offs inside the stack - it's faster than for loop */
268269
memcpy(&PL_savestack[PL_savestack_ix], rex->offs + parenfloor + 1, paren_bytes_to_push);

t/re/pat.t

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ skip_all_without_unicode_tables();
2727

2828
my $has_locales = locales_enabled('LC_CTYPE');
2929

30-
plan tests => 1230; # Update this when adding/deleting tests.
30+
plan tests => 1231; # Update this when adding/deleting tests.
3131

3232
run_tests() unless caller;
3333

@@ -2413,6 +2413,20 @@ SKIP:
24132413
is($y,"b","Branch reset in list context check 11 (b)");
24142414
is($z,"z","Branch reset in list context check 12 (z)");
24152415
}
2416+
TODO:{
2417+
local $::TODO = "Will be fixed next commit";
2418+
# Test for GH Issue #20826. Save stack overflow introduced in
2419+
# 92373dea9d7bcc0a017f20cb37192c1d8400767f PR #20530.
2420+
# Note this test depends on an assert so it will only fail
2421+
# under DEBUGGING.
2422+
fresh_perl_is(q{
2423+
$_ = "x" x 1000;
2424+
my $pat = '(.)' x 200;
2425+
$pat = qr/($pat)+/;
2426+
m/$pat/;
2427+
print "ok";
2428+
}, 'ok', {}, 'gh20826: test regex save stack overflow');
2429+
}
24162430
} # End of sub run_tests
24172431

24182432
1;

0 commit comments

Comments
 (0)