From 1b6655cf77b6081571eef2897b64196bc6b77fec Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 19 Aug 2020 15:23:34 +0900 Subject: [PATCH] Check sender validity on streaming related requests Change-Id: I648536f129462e4980a8b31e11e10d9dac996aac --- inc/service_main.h | 1 + src/service_main.cpp | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/inc/service_main.h b/inc/service_main.h index 414a3b9..766e512 100644 --- a/inc/service_main.h +++ b/inc/service_main.h @@ -157,6 +157,7 @@ private: bool check_preprocessing_assistant_exists(); ma_preprocessing_allow_mode_e get_preprocessing_allow_mode(const char* appid); bool is_current_preprocessing_assistant(const char* appid); + bool is_current_assistant(pid_t pid); private: std::string mCurrentLanguage{"en_US"}; diff --git a/src/service_main.cpp b/src/service_main.cpp index bb377a2..bbf3098 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -57,6 +57,24 @@ bool CServiceMain::check_preprocessing_assistant_exists() return ret; } +bool CServiceMain::is_current_assistant(pid_t pid) +{ + bool ret = false; + const char *current_maclient_appid = NULL; + if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) { + current_maclient_appid = mClientInfo[mCurrentClientInfo].appid; + pid_t pid_by_appid = mClientManager.find_client_pid_by_appid( + std::string{current_maclient_appid}); + if (pid == pid_by_appid) { + ret = true; + } else { + MAS_LOGE("[ERROR] Current client: [%d], active client : [%d %s]", + pid, pid_by_appid, current_maclient_appid); + } + } + return ret; +} + bool CServiceMain::is_current_preprocessing_assistant(const char* appid) { if (NULL == appid) return false; @@ -138,6 +156,8 @@ int CServiceMain::client_send_voice_key_status_change(pid_t pid, ma_voice_key_st int CServiceMain::client_send_asr_result(pid_t pid, int event, const char* asr_result) { MAS_LOGD("[Enter] pid(%d), event(%d), asr_result(%s)", pid, event, asr_result); + if (!is_current_assistant(pid)) return -1; + bool ui_panel_enabled = mServicePlugin.is_ui_panel_enabled(); int ret = 0; if (ui_panel_enabled) { @@ -156,6 +176,8 @@ int CServiceMain::client_send_result(pid_t pid, const char* display_text, const char* utterance_text, const char* result_json) { MAS_LOGD("[Enter] pid(%d), display_text(%s), utterance_text(%s), result_json(%s)", pid, display_text, utterance_text, result_json); + if (!is_current_assistant(pid)) return -1; + bool ui_panel_enabled = mServicePlugin.is_ui_panel_enabled(); int ret = 0; if (ui_panel_enabled) { @@ -178,6 +200,8 @@ int CServiceMain::client_send_result(pid_t pid, const char* display_text, int CServiceMain::client_send_recognition_result(pid_t pid, int result) { MAS_LOGD("[Enter] pid(%d), result(%d)", pid, result); + if (!is_current_assistant(pid)) return -1; + bool ui_panel_enabled = mServicePlugin.is_ui_panel_enabled(); int ret = 0; if (ui_panel_enabled) { @@ -200,18 +224,10 @@ int CServiceMain::client_send_recognition_result(pid_t pid, int result) int CServiceMain::client_start_streaming_audio_data(pid_t pid, int type) { MAS_LOGI("[ENTER"); + int ret = -1; - const char *current_maclient_appid = NULL; - if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) { - current_maclient_appid = mClientInfo[mCurrentClientInfo].appid; - pid_t pid_by_appid = mClientManager.find_client_pid_by_appid( - std::string{current_maclient_appid}); - if (pid != pid_by_appid) { - MAS_LOGE("[ERROR] Current client: [%d], active client : [%d %s]", - pid, pid_by_appid, current_maclient_appid); - return ret; - } - } + if (!is_current_assistant(pid)) return ret; + switch(type) { case MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE: ret = mServicePlugin.start_streaming_utterance_data(); @@ -232,6 +248,8 @@ int CServiceMain::client_start_streaming_audio_data(pid_t pid, int type) int CServiceMain::client_stop_streaming_audio_data(pid_t pid, int type) { int ret = -1; + if (!is_current_assistant(pid)) return ret; + switch(type) { case MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE: ret = mServicePlugin.stop_streaming_utterance_data(); @@ -270,6 +288,8 @@ int CServiceMain::client_set_assistant_specific_command(pid_t pid, const char *c int CServiceMain::client_set_background_volume(pid_t pid, double ratio) { + if (!is_current_assistant(pid)) return -1; + std::string pid_appid; boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); if (appid_by_pid) { -- 2.7.4