fix coverity issues 05/153405/3 accepted/tizen/unified/20171010.063635 submit/tizen/20170929.023936
authorJongkyu Koo <jk.koo@samsung.com>
Thu, 28 Sep 2017 09:05:17 +0000 (18:05 +0900)
committerJongkyu Koo <jk.koo@samsung.com>
Fri, 29 Sep 2017 02:06:58 +0000 (11:06 +0900)
Change-Id: Ic8ff60554a1567277d01ebce6c9c6e58882f67b2
Signed-off-by: Jongkyu Koo <jk.koo@samsung.com>
src/pims-ipc-worker.c

index d36c2fc..f3cd724 100644 (file)
@@ -206,6 +206,11 @@ static void __run_callback(int client_pid, char *call_id, pims_ipc_data_h dhandl
 {
        pims_ipc_svc_cb_s *cb_data = NULL;
 
+       if (client_pid < 0) {
+               DBG("invalid client_pid(%d)", client_pid);
+               return;
+       }
+
        VERBOSE("Call id [%s]", call_id);
 
        cb_data = g_hash_table_lookup(worker_cb_table, call_id);
@@ -322,6 +327,11 @@ static int _get_pid_from_fd(int fd)
        struct ucred uc;
        socklen_t uc_len = sizeof(uc);
 
+       if (fd < 0) {
+               DBG("invalid fd(%d)", fd);
+               return -1;
+       }
+
        if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &uc, &uc_len) < 0)
                ERR("getsockopt() Failed(%d)", errno);
 
@@ -360,7 +370,7 @@ static int __worker_loop_handle_raw_data(pims_ipc_worker_data_s *worker_data)
        } else
                __make_raw_data(raw_data->call_id, raw_data->seq_no, NULL, &result);
 
-       if (worker_data->client_fd != -1)
+       if (0 <= worker_data->client_fd)
                __send_raw_data(worker_data->client_fd, raw_data->client_id, result);
        worker_free_raw_data(raw_data);
        worker_free_raw_data(result);
@@ -425,10 +435,12 @@ static void* __worker_loop(void *data)
        int flag = fcntl(worker_data->client_fd, F_GETFL, 0);
        if (0 == (FD_CLOEXEC & flag)) {
                int client_pid = _get_pid_from_fd(worker_data->client_fd);
-               pthread_mutex_lock(&_worker_client_mutex);
-               g_hash_table_remove(worker_client_info_map, GINT_TO_POINTER(client_pid));
-               DBG("client pid(%u) is removed", client_pid);
-               pthread_mutex_unlock(&_worker_client_mutex);
+               if (0 <= client_pid) {
+                       pthread_mutex_lock(&_worker_client_mutex);
+                       g_hash_table_remove(worker_client_info_map, GINT_TO_POINTER(client_pid));
+                       DBG("client pid(%u) is removed", client_pid);
+                       pthread_mutex_unlock(&_worker_client_mutex);
+               }
        } else {
                DBG("fd(%d) is already closed", worker_data->client_fd);
        }
@@ -547,6 +559,11 @@ static int _create_client_info(int fd, pims_ipc_client_info_s **p_client_info)
        pid_t pid;
        char errmsg[1024] = {0};
 
+       if (fd < 0) {
+               DBG("invalid fd(%d)", fd);
+               return -1;
+       }
+
        pims_ipc_client_info_s *client_info = calloc(1, sizeof(pims_ipc_client_info_s));
        if (NULL == client_info) {
                ERR("calloc() return NULL");