From: dyamy-lee Date: Wed, 7 Feb 2024 03:27:40 +0000 (+0900) Subject: added null check after calling strdup X-Git-Tag: accepted/tizen/unified/20240315.111155~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d607ac186cf88b04072085366aba6243bd66511;p=platform%2Fcore%2Fuifw%2Fvoice-control.git added null check after calling strdup If there is no enough memory, strdup() can return null because of out of memory. For preventing it, this patch added null check Change-Id: I346b57d6dc28c03aa50c34315b05520401150edc --- diff --git a/client/vc_setting_tidl.c b/client/vc_setting_tidl.c index 686652f..9808020 100644 --- a/client/vc_setting_tidl.c +++ b/client/vc_setting_tidl.c @@ -69,11 +69,14 @@ static char* __get_engine_appid(void) engine_name = strdup("org.tizen.vc-engine-default"); } - char* appid = strdup(engine_name); + if (NULL == engine_name) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Out of memory"); + return NULL; + } - SLOG(LOG_INFO, TAG_VCC, "[INFO] VC engine appid(%s)", appid); + char* appid = engine_name; - free(engine_name); + SLOG(LOG_INFO, TAG_VCC, "[INFO] VC engine appid(%s)", appid); return appid; } @@ -223,6 +226,10 @@ int vc_setting_tidl_open_connection() int pid = getpid(); char* engine_appid = __get_engine_appid(); + if (NULL == engine_appid) { + SLOG(LOG_ERROR, TAG_VCC, "[TIDL ERROR] Fail to get engine appid"); + return VC_ERROR_OUT_OF_MEMORY; + } info->rpc_h = __create_rpc_port(pid, engine_appid); if (NULL == info->rpc_h) { diff --git a/client/vc_tidl.c b/client/vc_tidl.c index aad0435..5985b3e 100644 --- a/client/vc_tidl.c +++ b/client/vc_tidl.c @@ -78,11 +78,14 @@ static char* __get_engine_appid(void) engine_name = strdup("org.tizen.vc-engine-default"); } - char* appid = strdup(engine_name); + if (NULL == engine_name) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Out of memory"); + return NULL; + } - SLOG(LOG_INFO, TAG_VCC, "[INFO] VC engine appid(%s)", appid); + char* appid = engine_name; - free(engine_name); + SLOG(LOG_INFO, TAG_VCC, "[INFO] VC engine appid(%s)", appid); return appid; } @@ -370,6 +373,10 @@ int vc_tidl_open_connection() int pid = getpid(); info->pid = pid; info->engine_appid = __get_engine_appid(); + if (NULL == info->engine_appid) { + SLOG(LOG_ERROR, TAG_VCC, "[TIDL ERROR] Fail to get engine appid"); + return VC_ERROR_OUT_OF_MEMORY; + } info->rpc_h = __create_rpc_port(pid, info->engine_appid); if (NULL == info->rpc_h) { diff --git a/server/vcd_tidl.c b/server/vcd_tidl.c index 22dcb6f..fcdf952 100644 --- a/server/vcd_tidl.c +++ b/server/vcd_tidl.c @@ -1099,8 +1099,12 @@ static int __vc_mgr_get_private_data_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_conte temp_data = strdup("#NULL"); } - *data = strdup(temp_data); - free(temp_data); + if (NULL == temp_data) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Out of memory"); + return VC_ERROR_OUT_OF_MEMORY; + } + + *data = temp_data; SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr get private data : pid(%d), key(%s)", pid, key);