This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #126193] don't use a trash SV if no indexes are provided to pp_lslice
authorTony Cook <tony@develop-help.com>
Wed, 11 Nov 2015 04:57:09 +0000 (15:57 +1100)
committerTony Cook <tony@develop-help.com>
Tue, 17 Nov 2015 00:02:49 +0000 (11:02 +1100)
pp.c
t/op/list.t

diff --git a/pp.c b/pp.c
index 35a5f26..7301d8b 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -5268,15 +5268,20 @@ PP(pp_lslice)
     SV **lelem;
 
     if (GIMME_V != G_ARRAY) {
-       I32 ix = SvIV(*lastlelem);
-       if (ix < 0)
-           ix += max;
-       if (ix < 0 || ix >= max)
-           *firstlelem = &PL_sv_undef;
-       else
-           *firstlelem = firstrelem[ix];
-       SP = firstlelem;
-       RETURN;
+        if (lastlelem < firstlelem) {
+            *firstlelem = &PL_sv_undef;
+        }
+        else {
+            I32 ix = SvIV(*lastlelem);
+            if (ix < 0)
+                ix += max;
+            if (ix < 0 || ix >= max)
+                *firstlelem = &PL_sv_undef;
+            else
+                *firstlelem = firstrelem[ix];
+        }
+        SP = firstlelem;
+        RETURN;
     }
 
     if (max == 0) {
index c7056d0..9fe00a4 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     require "./test.pl";
 }
 
-plan( tests => 69 );
+plan( tests => 70 );
 
 @foo = (1, 2, 3, 4);
 cmp_ok($foo[0], '==', 1, 'first elem');
@@ -217,3 +217,6 @@ sub empty {}
 tie $t, "";
 () = (empty(), ($t)x10); # empty() since sub calls usually result in copies
 is(tied($t)->{fetched}, undef, 'assignment to empty list makes no copies');
+
+# this was passing a trash SV at the top of the stack to SvIV()
+ok(($0[()[()]],1), "[perl #126193] list slice with zero indexes");