From: YoungHun Kim Date: Thu, 20 May 2021 00:45:32 +0000 (+0900) Subject: Fix coverity issue X-Git-Tag: accepted/tizen/unified/20210601.135347^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7b867e8ff0f4c989215a000844a4ac5023fba7a2;p=platform%2Fcore%2Fmultimedia%2Fmmsvc-core.git Fix coverity issue - 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 --- diff --git a/client/src/muse_client.c b/client/src/muse_client.c index 197a8de..030ff1e 100644 --- a/client/src/muse_client.c +++ b/client/src/muse_client.c @@ -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; diff --git a/core/src/muse_core.c b/core/src/muse_core.c index 617c3fa..afab4a6 100644 --- a/core/src/muse_core.c +++ b/core/src/muse_core.c @@ -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); } diff --git a/packaging/mused.spec b/packaging/mused.spec index 717676f..7048630 100644 --- a/packaging/mused.spec +++ b/packaging/mused.spec @@ -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 diff --git a/server/src/muse_server_config.c b/server/src/muse_server_config.c index 4e51b18..b230e46 100644 --- a/server/src/muse_server_config.c +++ b/server/src/muse_server_config.c @@ -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]); } diff --git a/server/src/muse_server_log.c b/server/src/muse_server_log.c index fbec3ab..09836ca 100644 --- a/server/src/muse_server_log.c +++ b/server/src/muse_server_log.c @@ -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); diff --git a/server/src/muse_server_private.c b/server/src/muse_server_private.c index b1b7c97..ac872ea 100644 --- a/server/src/muse_server_private.c +++ b/server/src/muse_server_private.c @@ -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); diff --git a/server/src/muse_server_watchdog.c b/server/src/muse_server_watchdog.c index 772bb22..d1cc356 100644 --- a/server/src/muse_server_watchdog.c +++ b/server/src/muse_server_watchdog.c @@ -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; }