Permalink
Browse files

Fix segfault on blindly accessing foreign magic

We need to be more careful when introspecting arbitrary Perl 5 objects.
Other modules may attach '~' magic, so we need to check the presence of
a mg_ptr, before referencing it to access the magic key.
  • Loading branch information...
niner committed Nov 20, 2017
1 parent d7d908f commit 8431e318a9fd5e14c3b31561519ca0772589308a
Showing with 1 addition and 1 deletion.
  1. +1 −1 p5helper.c
View
@@ -912,7 +912,7 @@ int p5_is_wrapped_p6_object(PerlInterpreter *my_perl, SV *obj) {
SV * const obj_deref = SvRV(obj);
/* check for magic! */
MAGIC * const mg = mg_find(obj_deref, '~');
return (mg && ((_perl6_magic*)(mg->mg_ptr))->key == PERL6_MAGIC_KEY);
return (mg && mg->mg_ptr && ((_perl6_magic*)(mg->mg_ptr))->key == PERL6_MAGIC_KEY);
}
}

0 comments on commit 8431e31

Please sign in to comment.