This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add stack extend to Perl_die_unwind()
authorDavid Mitchell <davem@iabyn.com>
Fri, 27 Jan 2023 20:12:54 +0000 (20:12 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 16 Aug 2023 16:17:00 +0000 (17:17 +0100)
When invoked via a scalar-context eval, die_unwind() was pushing
&PL_sv_undef without extending the stack first. It's been this way for
many years. Spotted by visual inspection while adding rpp_() code.

I could get a SEGV with the following code, but I haven't added it as a
test as it's highly sensitive to exactly what size stack is initially
allocated and the OS's malloc().

    my $x;
    my @a =
        ($x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         $x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,$x,
         scalar eval { die },
    );

pp_ctl.c

index 8c5a2c3..4120d09 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2020,6 +2020,7 @@ Perl_die_unwind(pTHX_ SV *msv)
             /* return false to the caller of eval */
             gimme = cx->blk_gimme;
             if (gimme == G_SCALAR) {
+                rpp_extend(1);
                 if (rpp_stack_is_rc())
                     rpp_push_1(&PL_sv_undef);
                 else