Skip to content

Guard optional body field lookups against missing keys#18

Open
acts-1631 wants to merge 1 commit into
karlkleinpaste:masterfrom
acts-1631:fix/missing-optional-field-guard
Open

Guard optional body field lookups against missing keys#18
acts-1631 wants to merge 1 commit into
karlkleinpaste:masterfrom
acts-1631:fix/missing-optional-field-guard

Conversation

@acts-1631

Copy link
Copy Markdown

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; 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.

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.
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.

1 participant