fix use-after-free from dangling StringView in Blackboard::getKeys#1172
Open
aysha-afrah26 wants to merge 1 commit into
Open
fix use-after-free from dangling StringView in Blackboard::getKeys#1172aysha-afrah26 wants to merge 1 commit into
aysha-afrah26 wants to merge 1 commit into
Conversation
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.
getKeys() hands back a std::vector whose elements point into the std::string keys of the internal storage_ map. The shared lock added by the earlier BUG-6 fix is only held for the duration of getKeys() itself, so the returned views outlive it. ExportBlackboardToJSON walks those views after the lock is gone, and that path runs on the Groot2 publisher server thread in response to a BLACKBOARD request coming off the network. If the tree ticks an UnsetBlackboard node (or anything calling Blackboard::unset) in that window, unordered_map::erase destroys the key string and the StringView the exporter still holds now points at freed memory; constructing a std::string from it is a heap-use-after-free. I hit it while stress-testing concurrent key reads against unset, and ASan pins the read to the std::string copy in ExportBlackboardToJSON with the free coming from unset. The test file already had a note that getKeys() could dangle on erase, so this finishes that fix by returning owning std::string copies made under the lock instead of views into storage. Worth calling out that the return type changes from vector to vectorstd::string, a small API change; all in-tree callers already copied into std::string anyway. The added regression test reads keys while another thread erases and reports the use-after-free under ASan before the change, clean after.