RT #121721.
A subroutine call like &foo; pushes a SUB context with the savearray field
unassigned, and with CxHASARGS() false. Most of the core knows not to use
this field without CxHASARGS() being true: except for Perl_cx_dup(),
which was still trying to dup it. This could lead to SEGVs on a fresh CX
stack, or possibly duping some other sub's @_ on a reused stack entry.
The fix is simple; don't dup this field unless CxHASARGS() is set.
Note that a similar test is already in place for the argarray field.
? av_dup_inc(ncx->blk_sub.argarray,
param)
: NULL);
- ncx->blk_sub.savearray = av_dup_inc(ncx->blk_sub.savearray,
- param);
+ ncx->blk_sub.savearray = (CxHASARGS(ncx)
+ ? av_dup_inc(ncx->blk_sub.savearray,
+ param)
+ : NULL);
ncx->blk_sub.oldcomppad = (PAD*)ptr_table_fetch(PL_ptr_table,
ncx->blk_sub.oldcomppad);
break;
2
3
4
+########
+# this used to SEGV. RT # 121721
+$|=1;
+&main;
+sub main {
+ if (my $pid = fork) {
+ waitpid($pid, 0);
+ }
+ else {
+ print "foo\n";
+ }
+}
+EXPECT
+foo