This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t crash with ()=&CORE::srand
authorFather Chrysostomos <sprout@cpan.org>
Sun, 24 Jun 2012 18:14:29 +0000 (11:14 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 24 Jun 2012 18:14:29 +0000 (11:14 -0700)
Ops that don’t allow arbitrarily long argument lists are flagged at compile-time with the number of children.

Coresubs have to call the same op with differing numbers of arguments,
so they push nulls on to the stack to make up the number of items the
pp function expects to pop.

Commit f914a6829 stopped popping the null of the stack.

Before:
$ ./perl -le 'print &CORE::srand'
1240765685

After:
$ ./perl -le 'print &CORE::srand'
Bus error

List assignment does the same thing, and makes it easier to
write a test.

pp.c
t/op/coreamp.t

diff --git a/pp.c b/pp.c
index 1fcc885..156a500 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -2660,7 +2660,7 @@ PP(pp_srand)
     dVAR; dSP; dTARGET;
     UV anum;
 
-    if (MAXARG >= 1 && TOPs) {
+    if (MAXARG >= 1 && (TOPs || POPs)) {
         SV *top;
         char *pv;
         STRLEN len;
index 93e2c51..11ddc79 100644 (file)
@@ -802,6 +802,7 @@ test_proto 'sqrt', 4, 2;
 test_proto 'srand';
 $tests ++;
 &CORE::srand;
+() = &CORE::srand;
 pass '&srand with no args does not crash';
 
 test_proto 'study';