Commit 790fc60d authored by Omar Kallel's avatar Omar Kallel

Fix flawfinder errors

parent 164b97b9
Pipeline #10739 passed with stage
in 7 seconds
......@@ -92,9 +92,9 @@ mxml_node_t *bkp_session_insert_event(int index, char *command_key, int id, char
mxml_node_t *b;
pthread_mutex_lock(&mutex_backup_session);
sprintf(parent_name, "%s_event", status);
sprintf(event_id, "%d", id);
sprintf(event_idx, "%d", index);
snprintf(parent_name, sizeof(parent_name), "%s_event", status);
snprintf(event_id, sizeof(event_id), "%d", id);
snprintf(event_idx, sizeof(event_idx), "%d", index);
keys[0].name = "id";
keys[0].value = event_id;
b = bkp_session_node_found(bkp_tree, parent_name, keys, 1);
......@@ -116,8 +116,8 @@ void bkp_session_delete_event(int id, char *status)
mxml_node_t *b;
pthread_mutex_lock(&mutex_backup_session);
sprintf(parent_name, "%s_event", status);
sprintf(event_id, "%d", id);
snprintf(parent_name, sizeof(parent_name), "%s_event", status);
snprintf(event_id, sizeof(event_id), "%d", id);
keys[0].name = "id";
keys[0].value = event_id;
b = bkp_session_node_found(bkp_tree, parent_name, keys, 1);
......@@ -1641,7 +1641,7 @@ int bkp_session_check_file()
{
FILE *pFile;
if (access(CWMP_BKP_FILE, F_OK) == -1) {
if (!file_exists(CWMP_BKP_FILE)) {
bkp_session_create_file();
return -1;
}
......
......@@ -199,3 +199,10 @@ bool folder_exists(const char *path)
return (stat(path, &folder_stat) == 0 && S_ISDIR(folder_stat.st_mode));
}
bool file_exists(const char *path)
{
struct stat buffer;
return stat(path, &buffer) == 0;
}
......@@ -361,11 +361,11 @@ void cwmp_schedule_session(struct cwmp *cwmp)
retry = false;
}
session = list_entry(ilist, struct session, list);
if (access(DM_ENABLED_NOTIFY, F_OK) != -1) {
if (file_exists(DM_ENABLED_NOTIFY)) {
if (!event_exist_in_list(cwmp, EVENT_IDX_4VALUE_CHANGE))
is_notify = check_value_change();
}
if (is_notify > 0 || access(DM_ENABLED_NOTIFY, F_OK) < 0)
if (is_notify > 0 || !file_exists(DM_ENABLED_NOTIFY))
cwmp_update_enabled_notify_file();
cwmp_prepare_value_change(cwmp);
free_dm_parameter_all_fromlist(&list_value_change);
......@@ -379,7 +379,7 @@ void cwmp_schedule_session(struct cwmp *cwmp)
cwmp->session_status.last_status = SESSION_RUNNING;
cwmp->session_status.next_retry = 0;
if (access(fc_cookies, F_OK) != -1)
if (file_exists(fc_cookies))
remove(fc_cookies);
CWMP_LOG(INFO, "Start session");
......
......@@ -106,9 +106,9 @@ char *cwmp_uci_list_to_string(struct uci_list *list, char *delimitor)
int len = strlen(val);
if (len != 0) {
memcpy(val + len, delimitor, del_len);
strcpy(val + len + del_len, e->name);
strncpy(val + len + del_len, e->name, strlen(e->name));
} else
strcpy(val, e->name);
strncpy(val, e->name, strlen(e->name));
}
return (strdup(val));
} else {
......@@ -273,7 +273,7 @@ int cwmp_uci_get_value_common(char *cmd, char **value, bool state)
return CWMP_GEN_ERR;
}
if (state) {
strcpy(state_path, VARSTATE_CONFIG);
strncpy(state_path, VARSTATE_CONFIG, strlen(VARSTATE_CONFIG));
uci_add_delta_path(c, c->savedir);
uci_set_savedir(c, state_path);
}
......@@ -326,7 +326,7 @@ static int uci_action_value_common(char *cmd, uci_config_action action)
}
if (action == CWMP_CMD_SET_STATE) {
strcpy(state_path, VARSTATE_CONFIG);
strncpy(state_path, VARSTATE_CONFIG, strlen(VARSTATE_CONFIG));
uci_add_delta_path(c, c->savedir);
uci_set_savedir(c, state_path);
}
......
......@@ -105,7 +105,7 @@ void http_client_exit(void)
curl_slist_free_all(http_c.header_list);
http_c.header_list = NULL;
}
if (access(fc_cookies, W_OK) == 0)
if (file_exists(fc_cookies))
remove(fc_cookies);
curl_easy_cleanup(curl);
curl_global_cleanup();
......@@ -223,7 +223,7 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **
curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip);
if (ip && ip[0] != '\0') {
if (ip_acs[0] == '\0' || strcmp(ip_acs, ip) != 0) {
strcpy(ip_acs, ip);
strncpy(ip_acs, ip, strlen(ip));
if (cwmp->conf.ipv6_enable) {
tmp = inet_pton(AF_INET, ip, buf);
if (tmp == 1)
......@@ -383,7 +383,7 @@ void http_server_init(void)
break;
}
char buf[64];
sprintf(buf, UCI_CPE_PORT_PATH "=%d", cr_port);
snprintf(buf, sizeof(buf), UCI_CPE_PORT_PATH "=%d", cr_port);
uci_set_state_value(buf);
connection_request_port_value_change(&cwmp_main, cr_port);
CWMP_LOG(INFO, "Connection Request server initiated with the port: %d", cr_port);
......
......@@ -450,6 +450,7 @@ void cwmp_del_list_param_value(struct cwmp_param_value *param_value);
void cwmp_free_all_list_param_value(struct list_head *list_param_value);
int cwmp_asprintf(char **s, const char *format, ...);
bool folder_exists(const char *path);
bool file_exists(const char *path);
#ifndef FREE
#define FREE(x) \
......
......@@ -137,7 +137,7 @@ int kernel_api_cwmp_value_change_call(int count, ...)
if (kernel_cwmp_input.argv[i] == NULL) {
goto kernel_api_cwmp_error;
}
strcpy(kernel_cwmp_input.argv[i], s);
strncpy(kernel_cwmp_input.argv[i], s, sizeof(kernel_cwmp_input.argv[i]));
kernel_cwmp_input.argc++;
}
va_end(args);
......
......@@ -42,12 +42,13 @@ int log_set_severity_idx(char *value)
int log_set_log_file_name(char *value)
{
if (value != NULL) {
strcpy(log_file_name, value);
strncpy(log_file_name, value, strlen(value));
} else {
strcpy(log_file_name, DEFAULT_LOG_FILE_NAME);
strncpy(log_file_name, DEFAULT_LOG_FILE_NAME, strlen(DEFAULT_LOG_FILE_NAME));
}
return 1;
}
int log_set_file_max_size(char *value)
{
if (value != NULL) {
......@@ -55,6 +56,7 @@ int log_set_file_max_size(char *value)
}
return 1;
}
int log_set_on_console(char *value)
{
if (strcmp(value, "enable") == 0) {
......@@ -65,6 +67,7 @@ int log_set_on_console(char *value)
}
return 1;
}
int log_set_on_file(char *value)
{
if (strcmp(value, "enable") == 0) {
......@@ -118,16 +121,16 @@ void puts_log(int severity, const char *fmt, ...)
gettimeofday(&tv, 0);
Tm = localtime(&tv.tv_sec);
i = sprintf(buf, "%02d-%02d-%4d, %02d:%02d:%02d %s ", Tm->tm_mday, Tm->tm_mon + 1, Tm->tm_year + 1900, Tm->tm_hour, Tm->tm_min, Tm->tm_sec, SEVERITY_NAMES[severity]);
i = snprintf(buf, sizeof(buf), "%02d-%02d-%4d, %02d:%02d:%02d %s ", Tm->tm_mday, Tm->tm_mon + 1, Tm->tm_year + 1900, Tm->tm_hour, Tm->tm_min, Tm->tm_sec, SEVERITY_NAMES[severity]);
if (strlen(log_file_name) == 0) {
strcpy(log_file_name, DEFAULT_LOG_FILE_NAME);
strncpy(log_file_name, DEFAULT_LOG_FILE_NAME, strlen(DEFAULT_LOG_FILE_NAME));
}
if (enable_log_file) {
if (stat(log_file_name, &st) == 0) {
size = st.st_size;
}
if (size >= log_max_size) {
sprintf(log_file_name_bak, "%s.1", log_file_name);
snprintf(log_file_name_bak, sizeof(log_file_name_bak), "%s.1", log_file_name);
rename(log_file_name, log_file_name_bak);
pLog = fopen(log_file_name, "w");
} else {
......@@ -135,9 +138,9 @@ void puts_log(int severity, const char *fmt, ...)
}
}
va_start(args, fmt);
i += vsprintf(buf + i, fmt, args);
i += vsprintf(buf + i, (const char *)fmt, args);
if (enable_log_file) {
strcpy(buf_file, buf);
strncpy(buf_file, buf, strlen(buf));
strcat(buf_file, "\n");
fputs(buf_file, pLog);
}
......@@ -181,9 +184,9 @@ void puts_log_xmlmsg(int severity, char *msg, int msgtype)
gettimeofday(&tv, 0);
Tm = localtime(&tv.tv_sec);
sprintf(buf, "%02d-%02d-%4d, %02d:%02d:%02d %s ", Tm->tm_mday, Tm->tm_mon + 1, Tm->tm_year + 1900, Tm->tm_hour, Tm->tm_min, Tm->tm_sec, SEVERITY_NAMES[severity]);
snprintf(buf, sizeof(buf), "%02d-%02d-%4d, %02d:%02d:%02d %s ", Tm->tm_mday, Tm->tm_mon + 1, Tm->tm_year + 1900, Tm->tm_hour, Tm->tm_min, Tm->tm_sec, SEVERITY_NAMES[severity]);
if (strlen(log_file_name) == 0) {
strcpy(log_file_name, DEFAULT_LOG_FILE_NAME);
strncpy(log_file_name, DEFAULT_LOG_FILE_NAME, strlen(DEFAULT_LOG_FILE_NAME));
}
if (msgtype == XML_MSG_IN) {
......@@ -199,7 +202,7 @@ void puts_log_xmlmsg(int severity, char *msg, int msgtype)
size = st.st_size;
}
if (size >= log_max_size) {
sprintf(log_file_name_bak, "%s.1", log_file_name);
snprintf(log_file_name_bak, sizeof(log_file_name_bak), "%s.1", log_file_name);
rename(log_file_name, log_file_name_bak);
pLog = fopen(log_file_name, "w");
} else {
......
......@@ -483,7 +483,7 @@ const char *whitespace_cb(mxml_node_t *node, int where)
case MXML_WS_BEFORE_OPEN:
tab_space[0] = '\0';
while ((node = node->parent))
strcat(tab_space, CWMP_MXML_TAB_SPACE);
strncat(tab_space, CWMP_MXML_TAB_SPACE, strlen(CWMP_MXML_TAB_SPACE));
return tab_space;
case MXML_WS_AFTER_OPEN:
return ((!node->child || node->child->type == MXML_ELEMENT) ? "\n" : NULL);
......@@ -725,7 +725,7 @@ char *xml_get_cwmp_version(int version)
sprintf(tmp, "1.%d", k);
else
sprintf(tmp, ", 1.%d", k);
strcat(versions, tmp);
strncat(versions, tmp, strlen(tmp));
}
return versions;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment