From 36c02047bc819d5811405d9711e3cc501754949f Mon Sep 17 00:00:00 2001 From: Collin Date: Tue, 23 Nov 2021 10:18:51 -0500 Subject: Ensure valid application pointer in RAI::CheckLanguage and FinishSendingResponseToMobile (#3815) * don't use null application ptr in RAI::CheckLanguage or FinishSendingResponseToMobile * prevent application nullptr deref in SendRegisterAppInterfaceResponseToMobile * check application valid in ApplicationDataShouldBeResumed * restore ResumeCtrlImpl DCHECKs --- .../commands/mobile/register_app_interface_request.h | 2 +- .../mobile/register_app_interface_request.cc | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h index d54f061228..351c108573 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h @@ -301,7 +301,7 @@ class RegisterAppInterfaceRequest * @brief CheckLanguage check if language in RAI matches hmi_capabilities * Setup result_code variable in case of does not match */ - void CheckLanguage(); + void CheckLanguage(application_manager::ApplicationSharedPtr application); std::string response_info_; bool are_tts_chunks_invalid_; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc index 2224f17c4e..519d70e1d8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc @@ -274,6 +274,11 @@ bool RegisterAppInterfaceRequest::ApplicationDataShouldBeResumed( const uint32_t key = connection_key(); ApplicationSharedPtr application = application_manager_.application(key); + if (!application) { + SDL_LOG_DEBUG("Application not found, no resumption required"); + return false; + } + const bool hash_id_present = msg_params.keyExists(strings::hash_id); const std::string hash_id = msg_params[strings::hash_id].asString(); const bool resumption = hash_id_present && !hash_id.empty(); @@ -348,9 +353,8 @@ policy::StatusNotifier RegisterAppInterfaceRequest::AddApplicationDataToPolicy( application->mac_address(), application->policy_app_id(), hmi_types); } -void RegisterAppInterfaceRequest::CheckLanguage() { - ApplicationSharedPtr application = - application_manager_.application(connection_key()); +void RegisterAppInterfaceRequest::CheckLanguage( + ApplicationSharedPtr application) { DCHECK_OR_RETURN_VOID(application); const auto& msg_params = (*message_)[strings::msg_params]; if (msg_params[strings::language_desired].asInt() != @@ -430,6 +434,9 @@ void FinishSendingResponseToMobile(const smart_objects::SmartObject& msg_params, policy::StatusNotifier notify_upd_manager) { resumption::ResumeCtrl& resume_ctrl = app_manager.resume_controller(); auto application = app_manager.application(connection_key); + if (!application) { + return; + } policy::PolicyHandlerInterface& policy_handler = app_manager.GetPolicyHandler(); @@ -731,7 +738,7 @@ void RegisterAppInterfaceRequest::Run() { return; } - CheckLanguage(); + CheckLanguage(application); SendRegisterAppInterfaceResponseToMobile( ApplicationType::kNewApplication, status_notifier, add_info); @@ -874,6 +881,11 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( const uint32_t key = connection_key(); ApplicationSharedPtr application = application_manager_.application(key); + + if (!application) { + return; + } + utils::SemanticVersion negotiated_version = application->msg_version(); response_params[strings::sync_msg_version][strings::major_version] = -- cgit v1.2.1