Guard optional body field lookups against missing keys#18
Open
acts-1631 wants to merge 1 commit into
Open
Conversation
ReceiveInternal validates required body fields before processing,
but three optional fields are accessed via content.find(key)->second
without checking whether the key exists:
- BSP_APP_VERSION (app.version) all message types
- BSP_APP_DEVICE (app.device) CHAT, ANNOUNCE, BEACON
- BSP_MSG_SYNC_ALTVERSE (msg.sync.altVerse) SYNC
A packet that passes the required-field check but omits these
optional fields causes content.find() to return the past-the-end
iterator, and dereferencing ->second is undefined behavior. On
libstdc++ this manifests as std::bad_alloc (caught as a crash in
testing); other STL implementations may crash or silently propagate
garbage to the nav_func callback.
Guard each lookup with an existence check. The affected local
variables are already initialized to safe defaults ("<>" or empty),
so a missing field leaves the default in place.
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.
ReceiveInternal validates required body fields before processing, but
three optional fields are accessed via content.find(key)->second
without checking whether the key exists:
A packet that passes the required-field check but omits these
optional fields causes content.find() to return the past-the-end
iterator, and dereferencing ->second is undefined behavior. On
libstdc++ this manifests as std::bad_alloc; other STL implementations
may crash or silently propagate garbage to the nav_func callback.
This guards each lookup with an existence check. The affected local
variables are already initialized to safe defaults, so a missing
field leaves the default in place.