From c452e6ef57202f1e07f1e13d0c0c2e4294e0e6b1 Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Wed, 20 Jun 2018 13:13:09 -0400 Subject: add validity check to OnHMIStatusNotification::Run() to avoid passing bad default hmi level --- .../src/commands/mobile/on_hmi_status_notification.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/application_manager/src/commands/mobile/on_hmi_status_notification.cc b/src/components/application_manager/src/commands/mobile/on_hmi_status_notification.cc index 5225002652..8b5cca31fe 100644 --- a/src/components/application_manager/src/commands/mobile/on_hmi_status_notification.cc +++ b/src/components/application_manager/src/commands/mobile/on_hmi_status_notification.cc @@ -57,6 +57,16 @@ void OnHMIStatusNotification::Run() { return; } + // If the RPC was bad, give up now and don't try to check hmi level + if ((*message_)[strings::msg_params][strings::result_code] == + mobile_apis::Result::INVALID_DATA) { + SendNotification(); + // we failed due to invalid data, don't do anything else + return; + } + + // NOTE c++ maps default-construct on the [] operator, so if there is no + // hmiLevel field this will create one that is invalid mobile_apis::HMILevel::eType hmi_level = static_cast( (*message_)[strings::msg_params][strings::hmi_level].asInt()); -- cgit v1.2.1 From 1dd1640ec5673cda85039b20b3999169bc357511 Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Thu, 21 Jun 2018 11:06:14 -0400 Subject: Check for hmi level instead of status --- .../src/commands/mobile/on_hmi_status_notification.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/application_manager/src/commands/mobile/on_hmi_status_notification.cc b/src/components/application_manager/src/commands/mobile/on_hmi_status_notification.cc index 8b5cca31fe..a7453686e6 100644 --- a/src/components/application_manager/src/commands/mobile/on_hmi_status_notification.cc +++ b/src/components/application_manager/src/commands/mobile/on_hmi_status_notification.cc @@ -57,11 +57,10 @@ void OnHMIStatusNotification::Run() { return; } - // If the RPC was bad, give up now and don't try to check hmi level - if ((*message_)[strings::msg_params][strings::result_code] == - mobile_apis::Result::INVALID_DATA) { - SendNotification(); - // we failed due to invalid data, don't do anything else + // If the response has no hmi level, return and don't send the notification + if (!(*message_)[strings::msg_params].keyExists(strings::hmi_level)) { + // our notification clearly isn't well-formed + LOG4CXX_ERROR(logger_, "OnHMIStatusNotification has no hmiLevel field"); return; } -- cgit v1.2.1