Commit 8b8e1e3a authored by Vivek Kumar Dutta's avatar Vivek Kumar Dutta
Browse files

Fix null termination in strings

parent 8dd39df3
Pipeline #19369 passed with stages
in 5 minutes and 50 seconds
......@@ -7,6 +7,14 @@ source ./gitlab-ci/shared.sh
trap cleanup EXIT
trap cleanup SIGINT
echo "Starting dependent services"
supervisorctl status all
supervisorctl update
supervisorctl restart all
supervisorctl stop icwmpd
sleep 3
supervisorctl status all
echo "Compiling icmwp"
autoreconf -i
./configure --enable-acs=multi --enable-acs=hdm --enable-icwmp-test
......@@ -20,12 +28,6 @@ cp bin/.libs/libicwmp.so* /usr/lib
mkdir /usr/include/libicwmp
cp inc/*.h /usr/include/libicwmp
echo "Starting dependent services"
supervisorctl status all
supervisorctl update
sleep 3
supervisorctl status all
echo "Running the unit test cases"
make clean -C test/cmocka/
make unit-test -C test/cmocka/
......
......@@ -220,7 +220,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) {
strncpy(ip_acs, ip, strlen(ip));
snprintf(ip_acs, sizeof(ip_acs), "%s", ip);
if (cwmp->conf.ipv6_enable) {
tmp = inet_pton(AF_INET, ip, buf);
if (tmp == 1)
......
......@@ -72,7 +72,7 @@ static void kernel_api_cwmp_value_change_listener(struct sk_buff *skb)
nlh = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, msg_size, 0);
NETLINK_CB(skb_out).dst_group = 0; /* not in mcast group */
strncpy(nlmsg_data(nlh), msg, msg_size);
snprintf(nlmsg_data(nlh), msg_size, "%s", msg);
res = nlmsg_unicast(nl_sk, skb_out, pid);
if (i < kernel_cwmp_input.argc) {
......@@ -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;
}
strncpy(kernel_cwmp_input.argv[i], s, sizeof(kernel_cwmp_input.argv[i]));
snprintf(kernel_cwmp_input.argv[i], sizeof(kernel_cwmp_input.argv[i]), "%s", s);
kernel_cwmp_input.argc++;
}
va_end(args);
......
......@@ -42,9 +42,9 @@ int log_set_severity_idx(char *value)
int log_set_log_file_name(char *value)
{
if (value != NULL) {
strncpy(log_file_name, value, strlen(value));
snprintf(log_file_name, strlen(value), "%s", value);
} else {
strncpy(log_file_name, DEFAULT_LOG_FILE_NAME, strlen(DEFAULT_LOG_FILE_NAME));
snprintf(log_file_name, strlen(DEFAULT_LOG_FILE_NAME), "%s", DEFAULT_LOG_FILE_NAME);
}
return 1;
}
......@@ -121,7 +121,7 @@ void puts_log(int severity, const char *fmt, ...)
Tm = localtime(&tv.tv_sec);
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) {
strncpy(log_file_name, DEFAULT_LOG_FILE_NAME, strlen(DEFAULT_LOG_FILE_NAME));
snprintf(log_file_name, strlen(DEFAULT_LOG_FILE_NAME), "%s", DEFAULT_LOG_FILE_NAME);
}
if (enable_log_file) {
if (stat(log_file_name, &st) == 0) {
......@@ -181,7 +181,7 @@ void puts_log_xmlmsg(int severity, char *msg, int msgtype)
Tm = localtime(&tv.tv_sec);
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) {
strncpy(log_file_name, DEFAULT_LOG_FILE_NAME, strlen(DEFAULT_LOG_FILE_NAME));
snprintf(log_file_name, strlen(DEFAULT_LOG_FILE_NAME), "%s", DEFAULT_LOG_FILE_NAME);
}
if (msgtype == XML_MSG_IN) {
......
......@@ -56,8 +56,8 @@ static int itfcmp(char *itf1, char *itf2)
index = (int)(str - itf1);
if (!index)
goto end;
buf1 = malloc(index);
strncpy(buf1, itf1, index);
buf1 = malloc(index + 1);
snprintf(buf1, index + 1, "%s", itf1);
if (!buf1)
goto end;
buf1[index] = '\0';
......@@ -69,11 +69,11 @@ static int itfcmp(char *itf1, char *itf2)
index = (int)(str - itf2);
if (!index)
goto end;
buf2 = malloc(index);
buf2 = malloc(index + 1);
if (!buf2)
goto end;
buf2[index] = '\0';
strncpy(buf2, itf1, index);
snprintf(buf2, index+1, "%s", itf1);
if (strcmp(buf1, buf2) == 0)
status = 0;
end:
......
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