Fix svace issue 49/320549/2 accepted/tizen/unified/20241119.153901 accepted/tizen/unified/x/20241218.032652 accepted/tizen/unified/x/asan/20241224.004419
authorYoungHun Kim <yh8004.kim@samsung.com>
Mon, 18 Nov 2024 09:48:03 +0000 (18:48 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Mon, 18 Nov 2024 10:08:56 +0000 (19:08 +0900)
 - SEC_DO_NOT_ASSIGN_SIZE_OF_INT
   SEC_DO_NOT_CAST_LONG_TO_DOUBLE
   DEREF_OF_NULL.RET.STAT

Change-Id: I37129d3463ca68d2d532b634a82911a6822b0b37

packaging/mused.spec
server/include/muse_server_system.h
server/src/muse_server_private.c
server/src/muse_server_system.c

index ccc37a4af0daf6a41aaa76783ad89c30c2d79fa7..f00276ebc59638c364b08e759387b1f5e83339c6 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mused
 Summary:    A multimedia daemon
-Version:    0.4.8
+Version:    0.4.9
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 13fb39beabbc66f213c72cccd69dc5e68d2ae56b..2bb204ed458c6ad9ef4b52998d8bb7720cfc67f6 100644 (file)
@@ -47,7 +47,7 @@ typedef struct ms_cpu_jiffies {
        unsigned long long idle;
        guint id;
        int counter;
-       int usage;
+       double usage;
 } ms_cpu_jiffies_t;
 
 typedef struct ms_system {
index b8422223196ccce7561c60a02faca643e128ac1c..a98de326f741236344f6cf5a5699a5d4fadfa6fc 100644 (file)
@@ -159,7 +159,7 @@ static int _ms_new(muse_channel_e channel)
        int fd, errsv;
        mode_t m = 0;
        struct sockaddr_un addr_un;
-       socklen_t address_len;
+       long address_len;
        char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
 
        muse_return_val_if_fail(channel < MUSE_CHANNEL_MAX, MM_ERROR_INVALID_ARGUMENT);
@@ -179,13 +179,13 @@ static int _ms_new(muse_channel_e channel)
        memset(&addr_un, 0, sizeof(addr_un));
        addr_un.sun_family = AF_UNIX;
        strncpy(addr_un.sun_path, UDS_files[channel], sizeof(addr_un.sun_path) - 1);
-       address_len = (socklen_t)sizeof(addr_un);
+       address_len = sizeof(addr_un);
 
        if (!muse_server->daemonize)
                m = umask(0);
 
        /* Bind to filename */
-       if (bind(fd, (struct sockaddr *)&addr_un, address_len) < 0) {
+       if (bind(fd, (struct sockaddr *)&addr_un, (socklen_t)address_len) < 0) {
                errsv = errno;
                strerror_r(errsv, err_msg, MUSE_MSG_LEN_MAX);
                LOGE("[%d] socket bind failed (%d) %s", fd, errsv, err_msg);
@@ -220,10 +220,10 @@ static int _ms_get_pid(int fd)
 {
        char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
        struct ucred credentials;
-       socklen_t length;
+       long length;
 
-       length = (socklen_t)sizeof(struct ucred);
-       if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &credentials, &length) < 0) {
+       length = sizeof(struct ucred);
+       if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &credentials, (socklen_t *)&length) < 0) {
                strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
                LOGE("failed to get the value of credential type %s", err_msg);
                return MUSE_ERR;
@@ -268,7 +268,7 @@ static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition conditio
        int pid;
        int idx;
        int len;
-       socklen_t client_len;
+       long client_len;
        struct sockaddr_un client_address;
        muse_channel_e channel = GPOINTER_TO_INT(data);
        muse_module_h m = NULL;
@@ -307,10 +307,10 @@ static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition conditio
                goto out;
        }
 
-       client_len = (socklen_t)sizeof(client_address);
+       client_len = sizeof(client_address);
 
        LOGI("[%d] Try to accept...", server_sockfd);
-       client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, &client_len);
+       client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, (socklen_t *)&client_len);
        if (!muse_core_fd_is_valid(client_sockfd)) {
                LOGE("Critical Error : accept %d is invalid", client_sockfd);
                goto out;
@@ -498,6 +498,10 @@ static gpointer _ms_diag_check_connection_event_thread(gpointer data)
 
        while (ms_is_server_ready()) {
                dm = (ms_diag_msg_t *)g_async_queue_pop(d->msg_aq);
+               if (!dm) {
+                       LOGE("Failed to pop message from queue");
+                       break;
+               }
 
                LOGD("[%p] POP message (thread stop ? %d [%s])", dm, dm->thread_stop, ms_get_command_string(dm->cmd));
 
index 581aff65dbfc6955915287b0fc2cf110690831b4..493919eba5ab4106400e4f7f89d96c2725bc1fb1 100644 (file)
@@ -338,11 +338,11 @@ static gboolean _ms_system_cpu_usage_cb(gpointer user_data)
                return G_SOURCE_REMOVE;
        }
 
-       system->st.usage = (int)(100 * ((double)(u + n + s) / (u + n + s + i)));
-       LOGD("[#%d] cpu usage %d %%", system->st.counter, system->st.usage);
+       system->st.usage = 100 * ((double)(u + n + s) / (u + n + s + i));
+       LOGD("[#%d] cpu usage %.2f %%", system->st.counter, system->st.usage);
 
-       if (system->st.usage < cpu_threshold) {
-               LOGI("[#%d] cpu usage (%d) < cpu_threshold (%d)", system->st.counter, system->st.usage, cpu_threshold);
+       if ((int)system->st.usage < cpu_threshold) {
+               LOGI("[#%d] cpu usage (%.2f) < cpu_threshold (%d)", system->st.counter, system->st.usage, cpu_threshold);
                return G_SOURCE_REMOVE;
        }
 
@@ -352,7 +352,7 @@ static gboolean _ms_system_cpu_usage_cb(gpointer user_data)
                if (ms_get_instance())
                        ms_log_process_info(ms_get_instance()->pid);
 
-               snprintf(err_msg, sizeof(err_msg), "[CPU BUSY] %d >= %d %%", system->st.usage, cpu_threshold);
+               snprintf(err_msg, sizeof(err_msg), "[CPU BUSY] %.2f >= %d %%", system->st.usage, cpu_threshold);
 
                LOGE("%s", err_msg);
                ms_terminate(SIGTERM);