Fix linker callback leak for invalid UTF-8 names - #293
Open
grandpig wants to merge 1 commit into
Open
Conversation
Signed-off-by: grandpig <grandpig@outlook.com>
Member
|
Thanks for the PR, but I think the best fix here would be to fix the C API of Wasmtime itself. Would you be up for sending a PR there to run the destructors in the case that these fail? For example moving the closure construction earlier |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validate linker function module and name strings before storing their Go callbacks.
Linker.FuncNewandLinker.FuncWrappreviously inserted their callbacks into the global callback maps before callingwasmtime_linker_define_func.In Wasmtime v47,
wasmtime_linker_define_funcvalidates the module and name as UTF-8 before constructing the Rust callback closure:If either string contains invalid UTF-8, the C API returns before it takes ownership of data. Consequently, the Go finalizer is never called and the entry remains in gEngineFuncNew or gEngineFuncWrap, retaining the callback and everything captured by it.
This change:
Reproduction
Before this change, every call returned an error but added a permanent entry to the global callback map.