summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Cook <tony@develop-help.com>2015-11-04 11:03:36 +1100
committerTony Cook <tony@develop-help.com>2016-01-07 16:10:42 +1100
commit0cd52e23ae641a766983833dc8b37b743474be9e (patch)
tree7ff4f42bcba7af1e144be72616b4b15d845f06a8
parent8f1332ed63eb9a2061410b390e383415d456a7f4 (diff)
downloadperl-0cd52e23ae641a766983833dc8b37b743474be9e.tar.gz
[perl #126042] handle scalar context for a missing import/unimport call
-rw-r--r--pp_hot.c2
-rw-r--r--t/op/method.t19
2 files changed, 20 insertions, 1 deletions
diff --git a/pp_hot.c b/pp_hot.c
index f9790a267e..b29c347f4b 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -3347,6 +3347,8 @@ PP(pp_entersub)
SP = PL_stack_base + POPMARK;
else
(void)POPMARK;
+ if (GIMME_V == G_SCALAR)
+ PUSHs(&PL_sv_undef);
RETURN;
}
SvGETMAGIC(sv);
diff --git a/t/op/method.t b/t/op/method.t
index 1171f4a125..0d7f254053 100644
--- a/t/op/method.t
+++ b/t/op/method.t
@@ -13,7 +13,7 @@ BEGIN {
use strict;
no warnings 'once';
-plan(tests => 147);
+plan(tests => 148);
@A::ISA = 'B';
@B::ISA = 'C';
@@ -657,6 +657,23 @@ SKIP: {
like ($@, qr/Modification of a read-only value attempted/, 'RT #123619');
}
+{
+ # RT #126042 &{1==1} * &{1==1} would crash
+
+ # pp_entersub and pp_method_named cooperate to prevent calls to an
+ # undefined import() or unimport() method from croaking.
+ # If pp_method_named can't find the method it pushes &PL_sv_yes, and
+ # pp_entersub checks for that specific SV to avoid croaking.
+ # Ideally they wouldn't use that hack but...
+ # Unfortunately pp_entersub's handling of that case is broken in scalar context.
+
+ # Rather than using the test case from the ticket, since &{1==1}
+ # isn't documented (and may not be supported in future perls) test
+ # calls to undefined import method, which also crashes.
+ fresh_perl_is('Unknown->import() * Unknown->unimport(); print "ok\n"', "ok\n", {},
+ "check unknown import() methods don't corrupt the stack");
+}
+
__END__
#FF9900
#F78C08