Skip to content

Fix throw_ref missing null check on exnref#567

Merged
titzer merged 4 commits intotitzer:masterfrom
sumleo:fix/throw-ref-null-check
Mar 5, 2026
Merged

Fix throw_ref missing null check on exnref#567
titzer merged 4 commits intotitzer:masterfrom
sumleo:fix/throw-ref-null-check

Conversation

@sumleo
Copy link
Contributor

@sumleo sumleo commented Feb 25, 2026

Summary

  • THROW_REF pops an exnref and rethrows it but does not check for null before casting with Exception.!(exval.val), causing a crash on null exnref instead of trapping with NULL_DEREF.

Details

V3Interpreter.v3:330 — add a null check before the forced cast.

THROW_REF pops an exnref and rethrows it, but does not check for null
before casting with Exception.!(exval.val). A null exnref causes a
crash instead of properly trapping with NULL_DEREF.

Add null check before the cast to trap correctly.
Copy link
Owner

@titzer titzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, can you add a regression test for this case?

sumleo and others added 2 commits March 4, 2026 20:27
Verifies that throw_ref with a null exnref properly traps with
null dereference instead of crashing.
Comment change to trigger CI
}
THROW_REF => {
var exval = popr();
if (exval.val == null) return void(trap(TrapReason.NULL_DEREF));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regression test caught a bug in the fast interpreter, which calls into the runtime to do a throw. So we also need a line in X86_64Runtime.runtime_THROW_REF to check for null as well.

The fast interpreter runtime also needs to check for null throwable
before calling stack.throw(), matching the V3Interpreter null check.
@titzer titzer merged commit 73d41ed into titzer:master Mar 5, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants