-
Notifications
You must be signed in to change notification settings - Fork 267
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
runtime.InstantiateModule returns a "struct-wrapped" nil value #2353
Labels
bug
Something isn't working
Comments
edman
added a commit
to edman/wazero
that referenced
this issue
Dec 25, 2024
…bs#2353) Previously InstantiateModule could return a (*wasm.ModuleInstance)(nil) instead of a proper nil value. So callers could get a nil dereference panic in code like: m, _ := r.InstantiateModule(...) if m != nil { // this check passes defer m.Close() // but this causes a panic }
edman
added a commit
to edman/wazero
that referenced
this issue
Dec 25, 2024
…bs#2353) Previously InstantiateModule could return a (*wasm.ModuleInstance)(nil) instead of a proper nil value. So callers could get a nil dereference panic in code like: m, _ := r.InstantiateModule(...) if m != nil { // this check passes defer m.Close() // but this causes a panic }
edman
added a commit
to edman/wazero
that referenced
this issue
Dec 25, 2024
…bs#2353) Previously InstantiateModule could return a (*wasm.ModuleInstance)(nil) instead of a proper nil value. So callers could get a nil dereference panic in code like: m, _ := r.InstantiateModule(...) if m != nil { // this check passes defer m.Close() // but this causes a panic }
edman
added a commit
to edman/wazero
that referenced
this issue
Dec 25, 2024
…bs#2353) Previously InstantiateModule could return a (*wasm.ModuleInstance)(nil) instead of a proper nil value. So callers could get a nil dereference panic in code like: m, _ := r.InstantiateModule(...) if m != nil { // this check passes defer m.Close() // but this causes a panic } Signed-off-by: Edman Anjos <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
runtime.InstantiateModule
sometimes returns a "struct-wrapped"nil
value, instead of returning actualnil
.More specifically, this line https://github.com/tetratelabs/wazero/blob/main/runtime.go#L318 assigns
mod
and returns it implicitly on L324.This allows code like the following to panic with a nil pointer dereference because
m
isnil
:To Reproduce
Here is an example that mimics wazero's behavior: https://go.dev/play/p/66QShXidalq
Expected behavior
From https://go.dev/doc/faq#nil_error, the FAQ recommends:
Additional context
Found on sqlc-dev/sqlc#3759 (comment)
The text was updated successfully, but these errors were encountered: