added null check after calling strdup 29/305729/2
authordyamy-lee <dyamy.lee@samsung.com>
Wed, 7 Feb 2024 03:27:40 +0000 (12:27 +0900)
committerdyamy-lee <dyamy.lee@samsung.com>
Wed, 7 Feb 2024 09:34:02 +0000 (18:34 +0900)
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

client/vc_setting_tidl.c
client/vc_tidl.c
server/vcd_tidl.c

index 686652f..9808020 100644 (file)
@@ -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) {
index aad0435..5985b3e 100644 (file)
@@ -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) {
index 22dcb6f..fcdf952 100644 (file)
@@ -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);