From: Vitaliy Cherepanov Date: Wed, 7 Oct 2015 15:33:56 +0000 (+0300) Subject: [FIX] prevent issues X-Git-Tag: submit/tizen/20151105.065919~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e9cdbab762f1f8ac55101c2d986f3bf8e7efa3bc;p=platform%2Fcore%2Fsystem%2Fswap-manager.git [FIX] prevent issues ----------------------------------------------------------------------| | CID | Type | File | Function | |---------------------------------------------------------------------| |451069 | DC.SECURE_CODING_STRTOK | wsi.c | wsi_set_smack_rules | |451062 | DC.SECURE_CODING_SPRINTF | wsi.c | wsi_set_profile | |451061 | DC.SECURE_CODING_SPRINTF | utils.c | exec_app_common | |451060 | DC.SECURE_CODING_SPRINTF | wsi.c | init_wsi_conn | |451050 | ALLOC_FREE_MISMATCH | buffer.c | insert_buf_modules | |447744 | DC.SECURE_CODING_USLEEP | thread.c | replay_thread | |---------------------------------------------------------------------| Change-Id: Idb5ad86f483b27cca37566ac4250d9205412630f Signed-off-by: Vitaliy Cherepanov --- diff --git a/daemon/buffer.c b/daemon/buffer.c index 22c5ce2..52176a0 100644 --- a/daemon/buffer.c +++ b/daemon/buffer.c @@ -114,7 +114,7 @@ static int insert_buf_modules(void) if (f) { while (NULL != fgets(cmd, sizeof(cmd), f)) LOGE("start.sh >%s\n", cmd); - fclose(f); + pclose(f); } else { LOGE("Cannot open start.sh\n"); } diff --git a/daemon/threads.c b/daemon/threads.c index 8c97db1..4c9d835 100644 --- a/daemon/threads.c +++ b/daemon/threads.c @@ -410,7 +410,7 @@ static void *replay_thread(void *arg) print_replay_event(pevent, i + 1, "\t"); #endif LOGI_th_rep("%d) sleep %d\n", i, ms); - usleep(ms); + swap_usleep(ms); write_input_event(pevent->id, &pevent->ev); diff --git a/daemon/utils.c b/daemon/utils.c index c722d7f..bb9e841 100644 --- a/daemon/utils.c +++ b/daemon/utils.c @@ -177,8 +177,8 @@ int exec_app_common(const char* exec_path) return -1; } - sprintf(command, "%s", exec_path); - LOGI("cmd: %s\n", command); + snprintf(command, sizeof(command), "%s", exec_path); + LOGI("cmd: <%s>\n", command); pid = fork(); if (pid == -1) @@ -397,6 +397,7 @@ int kill_app(const char *binary_path) } else LOGI("cannot kill <%s>; process not found\n", binary_path); + LOGI("kill< %s (%d)\n", binary_path, FINISH_SIG); return 0; } @@ -480,3 +481,14 @@ float get_uptime(void) fclose(fp); return uptime; } + +void swap_usleep(useconds_t usec) +{ + struct timespec req; + struct timespec rem; + req.tv_sec = usec / 1000000; + req.tv_nsec = (usec % 1000000) * 1000; + if (nanosleep(&req, &rem) == -1) { + LOGW("sleep was terminated by signal\n"); + } +} diff --git a/daemon/wsi.c b/daemon/wsi.c index 8b74a3c..2fc929e 100644 --- a/daemon/wsi.c +++ b/daemon/wsi.c @@ -138,17 +138,17 @@ int wsi_set_profile(const struct app_info_t *app_info) if (ret) goto fail; - sprintf(info_tmp, "0x%lx", INSPECTOR_ADDR); + snprintf(info_tmp, sizeof(info_tmp), "0x%lx", INSPECTOR_ADDR); ret = set_profile_info(INSPSERVER_START_FILE, info_tmp); if (ret) goto fail; - sprintf(info_tmp, "0x%lx", WILLEXECUTE_ADDR); + snprintf(info_tmp, sizeof(info_tmp), "0x%lx", WILLEXECUTE_ADDR); ret = set_profile_info(WILL_EXECUTE_FILE, info_tmp); if (ret) goto fail; - sprintf(info_tmp, "0x%lx", DIDEXECUTE_ADDR); + snprintf(info_tmp, sizeof(info_tmp), "0x%lx", DIDEXECUTE_ADDR); ret = set_profile_info(DID_EXECUTE_FILE, info_tmp); if (ret) goto fail; @@ -166,6 +166,7 @@ int wsi_set_smack_rules(const struct app_info_t *app_info) int ret = 0; char *app_id; char *package_id; + char *tmp_ch; size_t id_maxlen = 128; app_id = strndup(app_info->app_id, id_maxlen); @@ -175,7 +176,8 @@ int wsi_set_smack_rules(const struct app_info_t *app_info) goto exit; } - package_id = strtok(app_id, delim); + /* TODO do not use strok_r function there */ + package_id = strtok_r(app_id, delim, &tmp_ch); if (package_id != NULL) { ret = apply_smack_rules(SUBJECT, package_id, ACCESS_TYPE); @@ -377,8 +379,8 @@ static int init_wsi_conn(struct libwebsocket_context **context, const char *page = "/devtools/page/1"; int ietf_version = -1; /* latest */ - sprintf(host, "%s:%d", address, port); - sprintf(origin, "http://%s:%d", address, port); + snprintf(host, sizeof(host), "%s:%d", address, port); + snprintf(origin, sizeof(origin), "http://%s:%d", address, port); LOGI(" host =<%s> origin = <%s>\n", host, origin); memset(&info, 0, sizeof(info));