diff options
author | Yves Orton <demerphq@gmail.com> | 2023-02-20 04:43:14 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-02-20 16:17:07 +0800 |
commit | bbf836262130e1ab1030c03e3b3b390c28c4bbda (patch) | |
tree | 3c467a5a8c53c87fc1ee3e4e03a0bbcbdcee60e4 | |
parent | 0a73ee9e231197058947bf0a854703757dc357ac (diff) | |
download | perl-bbf836262130e1ab1030c03e3b3b390c28c4bbda.tar.gz |
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.
-rw-r--r-- | regexec.c | 1 | ||||
-rw-r--r-- | t/re/pat.t | 16 |
2 files changed, 16 insertions, 1 deletions
@@ -263,6 +263,7 @@ S_regcppush(pTHX_ const regexp *rex, I32 parenfloor, U32 maxopenparen _pDEPTH) ); SSCHECK(total_elems + REGCP_FRAME_ELEMS); + assert((IV)PL_savestack_max > (IV)(total_elems + REGCP_FRAME_ELEMS)); /* memcpy the offs inside the stack - it's faster than for loop */ memcpy(&PL_savestack[PL_savestack_ix], rex->offs + parenfloor + 1, paren_bytes_to_push); diff --git a/t/re/pat.t b/t/re/pat.t index 2de4981195..d950c30ec9 100644 --- a/t/re/pat.t +++ b/t/re/pat.t @@ -27,7 +27,7 @@ skip_all_without_unicode_tables(); my $has_locales = locales_enabled('LC_CTYPE'); -plan tests => 1230; # Update this when adding/deleting tests. +plan tests => 1231; # Update this when adding/deleting tests. run_tests() unless caller; @@ -2413,6 +2413,20 @@ SKIP: is($y,"b","Branch reset in list context check 11 (b)"); is($z,"z","Branch reset in list context check 12 (z)"); } + TODO:{ + local $::TODO = "Will be fixed next commit"; + # Test for GH Issue #20826. Save stack overflow introduced in + # 92373dea9d7bcc0a017f20cb37192c1d8400767f PR #20530. + # Note this test depends on an assert so it will only fail + # under DEBUGGING. + fresh_perl_is(q{ + $_ = "x" x 1000; + my $pat = '(.)' x 200; + $pat = qr/($pat)+/; + m/$pat/; + print "ok"; + }, 'ok', {}, 'gh20826: test regex save stack overflow'); + } } # End of sub run_tests 1; |