Fix coverity issue 22/258522/4 accepted/tizen/unified/20210601.135347 submit/tizen/20210521.025641 submit/tizen/20210528.061611
authorYoungHun Kim <yh8004.kim@samsung.com>
Thu, 20 May 2021 00:45:32 +0000 (09:45 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Thu, 20 May 2021 03:01:56 +0000 (12:01 +0900)
 - Improper use of negative value (NEGATIVE_RETURNS)
 - Logically dead code (DEADCODE)
 - Out-of-bounds access (OVERRUN)
 - Data race condition (MISSING_LOCK)
 - Update strncmp() part totally

Change-Id: Ie6b23fb1281563522183a90e81048d15cea5207f

client/src/muse_client.c
core/src/muse_core.c
packaging/mused.spec
server/src/muse_server_config.c
server/src/muse_server_log.c
server/src/muse_server_private.c
server/src/muse_server_watchdog.c

index 197a8de..030ff1e 100644 (file)
@@ -345,7 +345,7 @@ int muse_client_get_module_index(const char *module_name, int *module_index)
 
        while (host) {
                g_strstrip(host);
-               if (strncmp(module_name, host, strlen(module_name) + 1) == 0) {
+               if (strncmp(module_name, host, strlen(module_name)) == 0) {
                        module_name_matched = true;
                        *module_index = idx;
                        break;
index 617c3fa..afab4a6 100644 (file)
@@ -863,7 +863,7 @@ void muse_core_remove_symlink(const char *path)
 
        r = realpath(path, NULL);
        if (r) {
-               if (strncmp(r, path, strlen(path) + 1) != 0) {
+               if (strncmp(r, path, strlen(path)) != 0) {
                        LOGW("symbolic link exists [%s] -> [%s]", path, r);
                        unlink(path);
                }
index 717676f..7048630 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mused
 Summary:    A multimedia daemon
-Version:    0.3.135
+Version:    0.3.136
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 4e51b18..b230e46 100644 (file)
@@ -73,7 +73,7 @@ static int _ms_config_parser(ms_config_t *conf)
 
        str = _ms_config_get_str(conf->muse_dict, MUSE_LOG, NULL);
        if (str) {
-               if (strncmp(str, MUSE_USE_LOG, strlen(MUSE_USE_LOG) + 1) == 0)
+               if (strncmp(str, MUSE_USE_LOG, strlen(MUSE_USE_LOG)) == 0)
                        conf->log_enabled = TRUE;
                else
                        conf->log_enabled = FALSE;
@@ -215,10 +215,10 @@ void ms_config_deinit(ms_config_t *conf)
        muse_return_if_fail(conf);
        muse_return_if_fail(conf->host_infos);
 
-       for (idx = 0; idx <= conf->host_cnt; idx++) {
-               MUSE_FREE(conf->host_infos[conf->host_cnt]->path);
-               MUSE_FREE(conf->host_infos[conf->host_cnt]->preloaded);
-               MUSE_FREE(conf->host_infos[conf->host_cnt]);
+       for (idx = 0; idx < conf->host_cnt; idx++) {
+               MUSE_FREE(conf->host_infos[idx]->path);
+               MUSE_FREE(conf->host_infos[idx]->preloaded);
+               MUSE_FREE(conf->host_infos[idx]);
                MUSE_FREE(conf->host[idx]);
        }
 
index fbec3ab..09836ca 100644 (file)
@@ -178,7 +178,7 @@ static void _ms_log_binary_info(ms_log_t *log)
        while (fgets(log_buf, MUSE_MSG_LEN_MAX, fp)) {
                label = strtok_r(log_buf, delimiter, &ptr);
                if (label) {
-                       if (strncmp(label, BUILD_ID, strlen(BUILD_ID) + 1) == 0) {
+                       if (strncmp(label, BUILD_ID, strlen(BUILD_ID)) == 0) {
                                value = strtok_r(NULL, delimiter, &ptr);
                                if (value)
                                        ms_log_write(value);
index b1b7c97..ac872ea 100644 (file)
@@ -304,6 +304,12 @@ static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition conditio
        LOGI("server : %d client [%s channel] : %d", server_sockfd, channel_name[channel], client_sockfd);
 
        pid = _ms_get_pid(client_sockfd);
+       if (pid == -1) {
+               close(client_sockfd);
+               _ms_unlock_state();
+               return FALSE;
+       }
+
 
        if (channel == MUSE_CHANNEL_MSG) {
                m = g_new0(muse_module_t, 1);
@@ -391,12 +397,8 @@ out:
        close(server_sockfd);
        close(client_sockfd);
 
-       if (m) {
-               if (channel == MUSE_CHANNEL_MSG)
-                       g_free(m);
-               else
-                       muse_core_connection_close(m->ch[MUSE_CHANNEL_MSG].sock_fd);
-       }
+       if (m)
+               muse_core_connection_close(m->ch[MUSE_CHANNEL_MSG].sock_fd);
 
        _ms_unlock_state();
 
@@ -723,7 +725,7 @@ void ms_fork(int *notify_fd)
                close(fds[0]);
 
                /* Parent process closes up output side of pipe */
-               if (!strcmp(msg, MSG_DONE)) {
+               if (!strncmp(msg, MSG_DONE, strlen(MSG_DONE))) {
                        LOGI("Successfully daemonized");
                        exit(EXIT_SUCCESS);
                } else {
@@ -974,7 +976,7 @@ void ms_init(char **argv)
        trace_begin("MUSE:preloading module");
 #endif
        for (idx = 0; idx < ms_config_get_host_cnt(); idx++) {
-               if (0 == strncmp(ms_config_get_preloaded_value(idx), "yes", strlen("yes") + 1)) {
+               if (0 == strncmp(ms_config_get_preloaded_value(idx), "yes", strlen("yes"))) {
                        g_module_symbol(ms_module_open(idx), CMD_DISPATCHER, (gpointer *)&cmd_dispatcher);
                        if (cmd_dispatcher && cmd_dispatcher[MUSE_MODULE_COMMAND_INITIALIZE])
                                cmd_dispatcher[MUSE_MODULE_COMMAND_INITIALIZE](NULL);
index 772bb22..d1cc356 100644 (file)
@@ -80,7 +80,10 @@ int ms_watchdog_init(ms_watchdog_t *watchdog)
 
        g_mutex_init(&watchdog->lock);
        g_cond_init(&watchdog->cond);
+
+       g_mutex_lock(&watchdog->lock);
        watchdog->run = TRUE;
+       g_mutex_unlock(&watchdog->lock);
 
        return MM_ERROR_NONE;
 }