Skip to content

Commit

Permalink
Ensure valid application pointer in RAI::CheckLanguage and FinishSend…
Browse files Browse the repository at this point in the history
…ingResponseToMobile (#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
  • Loading branch information
iCollin committed Nov 23, 2021
1 parent 1e88e6f commit 36c0204
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() !=
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -731,7 +738,7 @@ void RegisterAppInterfaceRequest::Run() {
return;
}

CheckLanguage();
CheckLanguage(application);

SendRegisterAppInterfaceResponseToMobile(
ApplicationType::kNewApplication, status_notifier, add_info);
Expand Down Expand Up @@ -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] =
Expand Down

0 comments on commit 36c0204

Please sign in to comment.