Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault when trying to print last element of nqp::backtrace() #3605

Closed
usev6 opened this issue Apr 5, 2020 · 1 comment · Fixed by MoarVM/MoarVM#1268
Closed

Segfault when trying to print last element of nqp::backtrace() #3605

usev6 opened this issue Apr 5, 2020 · 1 comment · Fixed by MoarVM/MoarVM#1268
Labels
MoarVM Related to Rakudo-MoarVM SEGV Segmentation fault, bus error, etc.

Comments

@usev6
Copy link
Contributor

usev6 commented Apr 5, 2020

The Problem

While hunting a NullPointerException on the JVM backend I've stumbled upon a segfault on MoarVM. The nqp::backtrace() that is used to produce the segfault stems from src/core.c/CallFrame.pm6 -- it's actually used in sub callframe.

$ ./rakudo-m -e 'use nqp; my $bt := nqp::backtrace(nqp::handle(nqp::die(""),"CATCH",nqp::exception)); say nqp::elems($bt)'
11
$ ./rakudo-m -e 'use nqp; my $bt := nqp::backtrace(nqp::handle(nqp::die(""),"CATCH",nqp::exception)); say $bt[10]'
Segmentation fault (core dumped)

Looking a bit further, it turns out that the key sub in that last element of that backtrace contains a NULL:

$ ./rakudo-m -e 'use nqp; my $bt := nqp::backtrace(nqp::handle(nqp::die(""),"CATCH",nqp::exception)); my $sub := nqp::atkey(nqp::getattr($bt[10],Map,"\$!storage"),"sub"); dd nqp::isnull($sub)'
1

If I'm not mistaken this NULL comes from this line: https://github.com/MoarVM/MoarVM/blob/c7e75be60a/src/core/exceptions.c#L576. Doing a NULL check there and falling back to tc->instance->VMNull seems to avoid the segmentation fault. But I don't know if that would be the correct fix.

Expected Behavior

Obviously, there should be no segfault. I'm not sure what the correct value for sub should be at that point.

Compiler version (perl6 -v):

This is Rakudo version 2020.02.1-289-g2cbf58372 built on MoarVM version 2020.02.1-71-g1bd5f19e0
implementing Raku 6.d.
@usev6 usev6 added MoarVM Related to Rakudo-MoarVM SEGV Segmentation fault, bus error, etc. labels Apr 5, 2020
@jnthn
Copy link
Member

jnthn commented Apr 5, 2020

Doing a NULL check there and falling back to tc->instance->VMNull seems to avoid the segmentation fault. But I don't know if that would be the correct fix.

yes, it would.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MoarVM Related to Rakudo-MoarVM SEGV Segmentation fault, bus error, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants