Skip to content
Permalink
Browse files

Make safely_stringify routine safer

Right now it doesn't check whether the Int/Str/List objects
are actually instances before trying to unbox them or peek at their
attributes, which causes explosions if the exception being
stringified has one of those types objects as a value.

Fix by printing '(Int)'/'(Str)'/'(List)' if the things are
type objects and aren't instances.
  • Loading branch information...
zoffixznet committed Jun 17, 2018
1 parent 60447c6 commit 0e2a7d93cbca88e770b89d9c17493d201d48d002
Showing with 7 additions and 3 deletions.
  1. +7 −3 src/Perl6/World.nqp
@@ -4969,17 +4969,21 @@ class Perl6::World is HLL::World {

sub safely_stringify($target) {
if $has_str && nqp::istype($target, $Str) {
return ~nqp::unbox_s($target);
return nqp::isconcrete($target)
?? ~nqp::unbox_s($target) !! '(Str)';
} elsif $has_int && nqp::istype($target, $Int) {
return ~nqp::unbox_i($target);
return nqp::isconcrete($target)
?? ~nqp::unbox_i($target) !! '(Int)';
} elsif $has_list && nqp::istype($target, $List) {
return '(List)' unless nqp::isconcrete($target);
my $storage := nqp::getattr($target, $List, '$!reified');
my @result;
for $storage {
nqp::push(@result, safely_stringify($_));
}
return "(" ~ join(", ", @result) ~ ")";
} elsif nqp::ishash($target) {
}
elsif nqp::ishash($target) {
my @result;
for $target -> $key {
@result.push("\n") if +@result != 0;

0 comments on commit 0e2a7d9

Please sign in to comment.
You can’t perform that action at this time.