fix coverity issues 52/202652/2 accepted/tizen_5.5_unified accepted/tizen_5.5_unified_mobile_hotfix accepted/tizen_5.5_unified_wearable_hotfix accepted/tizen_6.0_unified accepted/tizen_6.0_unified_hotfix accepted/tizen_6.5_unified accepted/tizen_7.0_unified accepted/tizen_7.0_unified_hotfix tizen_5.5 tizen_5.5_mobile_hotfix tizen_5.5_tv tizen_5.5_wearable_hotfix tizen_6.0 tizen_6.0_hotfix tizen_6.5 tizen_7.0 tizen_7.0_hotfix accepted/tizen/5.5/unified/20191031.004212 accepted/tizen/5.5/unified/mobile/hotfix/20201027.090910 accepted/tizen/5.5/unified/wearable/hotfix/20201027.113514 accepted/tizen/6.0/unified/20201030.115450 accepted/tizen/6.0/unified/hotfix/20201103.004207 accepted/tizen/6.5/unified/20211028.114448 accepted/tizen/7.0/unified/20221110.062648 accepted/tizen/7.0/unified/hotfix/20221116.105711 accepted/tizen/unified/20190404.075552 submit/tizen/20190403.234237 submit/tizen_5.5/20191031.000010 submit/tizen_5.5_mobile_hotfix/20201026.185104 submit/tizen_5.5_wearable_hotfix/20201026.184304 submit/tizen_6.0/20201029.205104 submit/tizen_6.0_hotfix/20201102.192504 submit/tizen_6.0_hotfix/20201103.114804 submit/tizen_6.5/20211028.162501 tizen_5.5.m2_release tizen_6.0.m2_release tizen_6.5.m2_release tizen_7.0_m2_release
authorwansuyoo <wansu.yoo@samsung.com>
Tue, 2 Apr 2019 07:40:39 +0000 (16:40 +0900)
committerwansuyoo <wansu.yoo@samsung.com>
Wed, 3 Apr 2019 23:24:00 +0000 (08:24 +0900)
- Leak of memory or pointers to system resources.
- A pointer to freed memory is dereferenced.

Change-Id: I269d33327e3534ecb14a019c9acfa12c19528b97
Signed-off-by: wansuyoo <wansu.yoo@samsung.com>
src/lib/ipc_client.c
src/parse_file.c
src/setup_system.c

index 8c0adcfd00daba03affe891c43d50a7871d638c3..8f8cf71c06ecec6432e64be564c0579efadb4e02 100755 (executable)
@@ -34,7 +34,6 @@ static int __client_open_connection(char *server, SOCKET_HANDLE* phndl)
        printf("<<Client>> __client_open_connection\n");
        ret = IPC_OpenClientConnection(server, phndl);
        if (0 == ret)   {
-               printf("<<Client>> phndl->server_h = %d\n", phndl->server_h);
                printf("<<Client>> phndl->client_h = %d\n", phndl->client_h);
        }       else {
                printf("<<Client>> connection_init ERROR(%d) !!! {%s}\n", ret, SERVER);
index ae3a67b4c16b632275645515c7e55d240e4def8e..59ed21241d49c01d16f83bb2b1125820ae0a7a61 100644 (file)
@@ -408,17 +408,22 @@ int __get_jsonobj_from_file(struct json_object **jsonObj, char *file_name)
 
 int __create_system_config_file(struct json_object *jsonObj, char *write_file)
 {
-       int ret = 0;
+       int ret = 0, rv = 0;
 
        if (jsonObj) {
                struct json_object *jsonObjVer = NULL;  // extract version object
 
                // prepare json objects
-               json_object_object_get_ex(jsonObj, "version", &jsonObjVer);
-               json_object_object_del(jsonObj, "wifi");
-               json_object_object_del(jsonObj, "ethernet");
+               if (json_object_object_get_ex(jsonObj, "version", &jsonObjVer)) {
+                       json_object_object_del(jsonObj, "wifi");
+                       json_object_object_del(jsonObj, "ethernet");
 
-               json_object_to_file_ext(write_file, jsonObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+                       rv = json_object_to_file_ext(write_file, jsonObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+                       if (rv < 0)
+                               ret = -1;
+               } else {
+                       ret = -1;
+               }
        } else {
                ret = -1;
        }
@@ -428,23 +433,31 @@ int __create_system_config_file(struct json_object *jsonObj, char *write_file)
 
 int __create_target_config_file(struct json_object *jsonObj, char *write_file)
 {
-       int ret = 0;
+       int ret = 0, rv = 0;
 
        if (jsonObj) {
                struct json_object *jsonObjVer = NULL;  // extract version object
                struct json_object *jsonObjName = NULL; // extract deviceName object
 
                // prepare json objects
-               json_object_object_get_ex(jsonObj, "version", &jsonObjVer);
-               json_object_object_get_ex(jsonObj, "deviceName", &jsonObjName);
+               if (json_object_object_get_ex(jsonObj, "version", &jsonObjVer)) {
+                       if (json_object_object_get_ex(jsonObj, "deviceName", &jsonObjName)) {
 
-               // result string for target
-               struct json_object *jsonObjResultTarget = json_object_new_object();
-               json_object_object_add(jsonObjResultTarget, "version", jsonObjVer);
-               if (jsonObjName)
-                       json_object_object_add(jsonObjResultTarget, "deviceName", jsonObjName);
+                               // result string for target
+                               struct json_object *jsonObjResultTarget = json_object_new_object();
+                               json_object_object_add(jsonObjResultTarget, "version", jsonObjVer);
+                               if (jsonObjName)
+                                       json_object_object_add(jsonObjResultTarget, "deviceName", jsonObjName);
 
-               json_object_to_file_ext(write_file, jsonObjResultTarget, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+                               rv = json_object_to_file_ext(write_file, jsonObjResultTarget, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+                               if (rv < 0)
+                                       ret = -1;
+                       } else {
+                               ret = -1;
+                       }
+               } else {
+                       ret = -1;
+               }
        } else {
                ret = -1;
        }
index fdff19e804faf6e9255473655a46aaa61ebb71c6..e41da0bf8733156ccf22ae849733075348d07915 100644 (file)
@@ -167,11 +167,11 @@ static sa_error_e sa_inputfile_set_proxy_env(sa_proxy_s * proxy)
                fd = open(ENVIRONMENT_PROXY_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644);
                if (fd > 0) {
                        write(fd, writeBuff, strlen(writeBuff));
-                       close(fd);
                } else {
                        ret = SA_ERROR_NOT_AVAILABLE;
                        _E("Cannot open file");
                }
+               close(fd);
        }
 
        return ret;
@@ -228,11 +228,11 @@ static sa_error_e sa_inputfile_set_dockerd_opt(sa_dockerd_opt_s * opt)
                fd = creat(CONFIG_DOCKERD_DAEMON_FILE, 0644);
                if (fd > 0) {
                        write(fd, buf, strlen(buf));
-                       close(fd);
                } else {
                        ret = SA_ERROR_NOT_AVAILABLE;
                        _E("Cannot create file");
                }
+               close(fd);
 
                if (buf != NULL)
                        free(buf);
@@ -355,17 +355,21 @@ void setup_user_certificates(void)
        if (dir_info != NULL) {
                while (dir_entry = readdir(dir_info)) {
                        if (__get_file_extension(dir_entry->d_name, &fileExt) == 0) {
-                               if (strncmp(fileExt, "crt", 3) == 0) {
-                                       snprintf(file_name, sizeof(file_name), "%s%s", USER_CERT_DIR_PATH, dir_entry->d_name);
-                                       if (__search_str_pattern(SYSTEM_CERT_FILE, file_name) != 0) {   // un-matched file, need to be applied
-                                               if (__apply_ca_cert_file(file_name) != 0)
-                                                       _D("File[%s]: apply error!!!", dir_entry->d_name);
-                                               else
-                                                       _D("File[%s]: applied successfully ca-certificate!!!", dir_entry->d_name);
-                                       } else
-                                               _D("FILE[%s]: already applied!!!", dir_entry->d_name);
+                               if (fileExt != NULL) {
+                                       if (strncmp(fileExt, "crt", 3) == 0) {
+                                               snprintf(file_name, sizeof(file_name), "%s%s", USER_CERT_DIR_PATH, dir_entry->d_name);
+                                               if (__search_str_pattern(SYSTEM_CERT_FILE, file_name) != 0) {   // un-matched file, need to be applied
+                                                       if (__apply_ca_cert_file(file_name) != 0)
+                                                               _D("File[%s]: apply error!!!", dir_entry->d_name);
+                                                       else
+                                                               _D("File[%s]: applied successfully ca-certificate!!!", dir_entry->d_name);
+                                               } else {
+                                                       _D("FILE[%s]: already applied!!!", dir_entry->d_name);
+                                               }
+                                       }
+                                       free(fileExt);
+                                       fileExt = NULL;
                                }
-                               free(fileExt);
                        } else
                                _D("File[%s]: Not valid certificate file", dir_entry->d_name);
                }
@@ -617,6 +621,7 @@ int sa_get_os_info(os_info_s * os_info_h)
 
                        _D("platformVer[%s]", os_info_h->platformVer);
                        free(ret_buf);
+                       ret_buf = NULL;
                }
                // get base OS version
                ret = CLI_command(GET_BASEOS_VERSION_CMD, 1, &ret_buf);
@@ -628,6 +633,7 @@ int sa_get_os_info(os_info_s * os_info_h)
 
                        _D("baseOSVer[%s]", os_info_h->baseOSVer);
                        free(ret_buf);
+                       ret_buf = NULL;
                }
                // get docker version
                ret = CLI_command(GET_DOCKER_VERSION_CMD, 1, &ret_buf);
@@ -639,6 +645,7 @@ int sa_get_os_info(os_info_s * os_info_h)
 
                        _D("dockerVer[%s]", os_info_h->dockerVer);
                        free(ret_buf);
+                       ret_buf = NULL;
                }
        }