Skip to content

fix: add null checks for std::get_if<EncodableMap> call sites#241

Open
aki1770-del wants to merge 1 commit into
toyota-connected:v2.0from
aki1770-del:fix/null-check-get-if-args
Open

fix: add null checks for std::get_if<EncodableMap> call sites#241
aki1770-del wants to merge 1 commit into
toyota-connected:v2.0from
aki1770-del:fix/null-check-get-if-args

Conversation

@aki1770-del

Copy link
Copy Markdown

Problem

std::get_if<EncodableMap>() returns nullptr when the Flutter method call argument is not an EncodableMap (e.g., wrong type or missing arguments). All affected call sites dereference the pointer unconditionally with *args, which is undefined behavior and causes an IVI HMI crash.

Fixes: #226

Changes

Added an explicit null check with result->Error() before every *args dereference across 6 plugins:

Plugin File Call sites fixed
secure_storage messages.cc 1
camera messages.cc 6
audioplayers_linux messages.cc 1
nav_render_view nav_render_texture.cc 1
pdf messages.cc 2
desktop_window_linux messages.cc 7

Total: 18 call sites guarded.

Fix pattern

// Before
const auto& args = std::get_if<EncodableMap>(call.arguments());
for (const auto& [fst, snd] : *args) { ... }  // UB if args == nullptr

// After
const auto& args = std::get_if<EncodableMap>(call.arguments());
if (!args) {
  result->Error("argument_error", "Expected map arguments");
  return;  // return std::nullopt for desktop_window_linux
}
for (const auto& [fst, snd] : *args) { ... }

Verification

  • Zero deletions — existing logic is unchanged
  • Each guard returns a typed error instead of crashing
  • desktop_window_linux uses return std::nullopt to match the surrounding lambda return type

Signed-off-by: Akihiro Komada aki1770@gmail.com

std::get_if returns nullptr when the argument type does not match the
requested variant alternative. Dereferencing the nullptr causes undefined
behavior. Add an explicit null check with result->Error() before every
dereference across 6 plugins (secure_storage, camera, audioplayers_linux,
nav_render_view, pdf, desktop_window_linux).

Fixes: toyota-connected#226

Signed-off-by: Akihiro Komada <aki1770@gmail.com>
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.

Null Pointer Dereference — std::get_if Without Null Check (Multiple Plugins)

1 participant