diff options
author | Tony Cook <tony@develop-help.com> | 2015-12-17 15:14:58 +1100 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2015-12-17 15:14:58 +1100 |
commit | dc9ef9989ca4dc4207da49f653e8789816f50a11 (patch) | |
tree | 32e8142288dc631bca78af658bf53102d88ab256 /t/op/sort.t | |
parent | 68bcb860c817a4691f45504f9563923c5ab2f6da (diff) | |
download | perl-dc9ef9989ca4dc4207da49f653e8789816f50a11.tar.gz |
[perl #124097] don't let the GPs be removed out from under pp_sort
pp_sort() saves the SV pointers for *a and *b, if the sort block
cleared *a or *b the GP, which the pointer is stored would be freed
and the save stack processing would try to write to freed memory.
Make sure the GP lasts at least long enough for the SV slots to be
restored. This doesn't attempt to restore *a or *b, the user chose
to clear them.
Diffstat (limited to 't/op/sort.t')
-rw-r--r-- | t/op/sort.t | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/t/op/sort.t b/t/op/sort.t index 3c76365140..22d83a9ea1 100644 --- a/t/op/sort.t +++ b/t/op/sort.t @@ -7,7 +7,7 @@ BEGIN { set_up_inc('../lib'); } use warnings; -plan(tests => 193); +plan(tests => 195); # these shouldn't hang { @@ -1127,3 +1127,14 @@ pass "no crash when sort block deletes *a and *b"; ::is (join('-', sort f2 3,1,2,4), '1-2-3-4', "Ret: f2"); ::is (join('-', sort f3 3,1,2,4), '1-2-3-4', "Ret: f3"); } + +{ + @a = sort{ *a=0; 1} 0..1; + pass "No crash when GP deleted out from under us [perl 124097]"; + + no warnings 'redefine'; + # some alternative non-solutions localized modifications to *a and *b + sub a { 0 }; + @a = sort { *a = sub { 1 }; $a <=> $b } 0 .. 1; + ok(a(), "*a wasn't localized inadvertantly"); +} |