diff options
author | wansuyoo <wansu.yoo@samsung.com> | 2019-04-02 16:40:39 +0900 |
---|---|---|
committer | wansuyoo <wansu.yoo@samsung.com> | 2019-04-04 08:24:00 +0900 |
commit | 7fbfd44e0c48d34f6ae74083314dbb68c7935a04 (patch) | |
tree | ef61b8463e82742d164cda81f39ec291c8019c85 | |
parent | d6451cb38d999a4e34adacd456ec8a02ed2bc476 (diff) | |
download | docker-adaptor-tizen_7.0.tar.gz docker-adaptor-tizen_7.0.tar.bz2 docker-adaptor-tizen_7.0.zip |
fix coverity issuestizen_7.0_m2_releasetizen_6.5.m2_releasetizen_6.0.m2_releasetizen_5.5.m2_releasesubmit/tizen_6.5/20211028.162501submit/tizen_6.0_hotfix/20201103.114804submit/tizen_6.0_hotfix/20201102.192504submit/tizen_6.0/20201029.205104submit/tizen_5.5_wearable_hotfix/20201026.184304submit/tizen_5.5_mobile_hotfix/20201026.185104submit/tizen_5.5/20191031.000010submit/tizen/20190403.234237accepted/tizen/unified/20190404.075552accepted/tizen/7.0/unified/hotfix/20221116.105711accepted/tizen/7.0/unified/20221110.062648accepted/tizen/6.5/unified/20211028.114448accepted/tizen/6.0/unified/hotfix/20201103.004207accepted/tizen/6.0/unified/20201030.115450accepted/tizen/5.5/unified/wearable/hotfix/20201027.113514accepted/tizen/5.5/unified/mobile/hotfix/20201027.090910accepted/tizen/5.5/unified/20191031.004212tizen_7.0_hotfixtizen_7.0tizen_6.5tizen_6.0_hotfixtizen_6.0tizen_5.5_wearable_hotfixtizen_5.5_tvtizen_5.5_mobile_hotfixtizen_5.5accepted/tizen_7.0_unified_hotfixaccepted/tizen_7.0_unifiedaccepted/tizen_6.5_unifiedaccepted/tizen_6.0_unified_hotfixaccepted/tizen_6.0_unifiedaccepted/tizen_5.5_unified_wearable_hotfixaccepted/tizen_5.5_unified_mobile_hotfixaccepted/tizen_5.5_unified
- 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>
-rwxr-xr-x | src/lib/ipc_client.c | 1 | ||||
-rw-r--r-- | src/parse_file.c | 41 | ||||
-rw-r--r-- | src/setup_system.c | 31 |
3 files changed, 46 insertions, 27 deletions
diff --git a/src/lib/ipc_client.c b/src/lib/ipc_client.c index 8c0adcf..8f8cf71 100755 --- a/src/lib/ipc_client.c +++ b/src/lib/ipc_client.c @@ -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); diff --git a/src/parse_file.c b/src/parse_file.c index ae3a67b..59ed212 100644 --- a/src/parse_file.c +++ b/src/parse_file.c @@ -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; } diff --git a/src/setup_system.c b/src/setup_system.c index fdff19e..e41da0b 100644 --- a/src/setup_system.c +++ b/src/setup_system.c @@ -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; } } |