This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
(perl #133989) scalar() the argument to readline, if any
authorTony Cook <tony@develop-help.com>
Wed, 12 Jun 2019 05:21:47 +0000 (15:21 +1000)
committerTony Cook <tony@develop-help.com>
Mon, 17 Jun 2019 04:45:16 +0000 (14:45 +1000)
C< readline @foo > would treat @foo as array.  If the array was empty
this would push zero items and readline() would then pop one item,
possibly underflowing the stack.

op.c
t/lib/croak/pp_sys

diff --git a/op.c b/op.c
index 6ad1923..7aa002c 100644 (file)
--- a/op.c
+++ b/op.c
@@ -12142,6 +12142,7 @@ Perl_ck_readline(pTHX_ OP *o)
     if (o->op_flags & OPf_KIDS) {
         OP *kid = cLISTOPo->op_first;
         if (kid->op_type == OP_RV2GV) kid->op_private |= OPpALLOW_FAKE;
+         scalar(kid);
     }
     else {
        OP * const newop
index be100da..cf9e4ef 100644 (file)
@@ -93,3 +93,9 @@ close $fh;
 END { unlink $file; }
 EXPECT
 syswrite() isn't allowed on :utf8 handles at - line 5.
+########
+# NAME readline() didn't scalar() its argument
+# this would assert rather than failing on the method call
+E{0;readline@0}
+EXPECT
+Can't call method "E" without a package or object reference at - line 2.