From: Zhimin Date: Fri, 8 May 2020 18:07:33 +0000 (+0800) Subject: change all the sprintf to snprintf to address the potential buffer/stack overflow X-Git-Tag: oran_release_bronze_v1.0~12 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=o-du%2Fphy.git;a=commitdiff_plain;h=afaa7b205ebe18aaa4ddb2cea457c647df2a3444 change all the sprintf to snprintf to address the potential buffer/stack overflow Change-Id: Ia25063b655113feb8b7e95e673d8aba373e44abc Signed-off-by: Zhimin --- diff --git a/example_odulow_build.txt b/example_odulow_build.txt deleted file mode 100644 index 8ef4f8d..0000000 --- a/example_odulow_build.txt +++ /dev/null @@ -1,44 +0,0 @@ -#! /bin/bash -# This is an example on how the different dependencies of the odulow fhi_lib can be brought into a build server -# which currently is the only module being built under odulow. -# In the example illustrated here we use a Centos OS in the server so the user should adopt the proper procedures -# for their target OS if it is different than Centos -cd /etc/yum.repos.d/ -mkdir backup; -mv *.repo backup; - -curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo -yum makecache - -yum install vim gcc-c++ libhugetlbfs* libstdc++* kernel-devel numa* gcc git mlocate xorg-x11-server-Xorg -y -cd /home -mkdir odu_low_test -cd /home/odu_low_test - -wget http://fast.dpdk.org/rel/dpdk-18.08.1.tar.xz -xz -d dpdk-18.08.1.tar.xz -tar -xvf dpdk-18.08.1.tar -mv dpdk-stable-18.08.1 dpdk-18.08 - -cd dpdk-18.08/usertools/ - -./dpdk-setup.sh<bbdev_mode == XRAN_BBDEV_MODE_HW_ON){ // hw-accelerated bbdev printf("hw-accelerated bbdev %s\n", io_cfg->bbdev_dev[0]); - sprintf(bbdev_wdev, "-w %s", io_cfg->bbdev_dev[0]); + snprintf(bbdev_wdev, sizeof(bbdev_wdev), "-w %s", io_cfg->bbdev_dev[0]); } else if (io_cfg->bbdev_mode == XRAN_BBDEV_MODE_HW_OFF){ // hw-accelerated bbdev disable if(io_cfg->bbdev_dev[0]){ printf("hw-accelerated bbdev disable %s\n", io_cfg->bbdev_dev[0]); - sprintf(bbdev_wdev, "-b %s", io_cfg->bbdev_dev[0]); + snprintf(bbdev_wdev, sizeof(bbdev_wdev), "-b %s", io_cfg->bbdev_dev[0]); } - sprintf(bbdev_wdev, "%s", "--vdev=baseband_turbo_sw"); + snprintf(bbdev_wdev, sizeof(bbdev_wdev), "%s", "--vdev=baseband_turbo_sw"); } else { rte_panic("Cannot init DPDK incorrect [bbdev_mode %d]\n", io_cfg->bbdev_mode); } diff --git a/fhi_lib/lib/src/xran_sync_api.c b/fhi_lib/lib/src/xran_sync_api.c index 5b1295f..873c2c1 100644 --- a/fhi_lib/lib/src/xran_sync_api.c +++ b/fhi_lib/lib/src/xran_sync_api.c @@ -71,7 +71,7 @@ static int is_process_running(char *pname) long pid = atol(entry->d_name); if (0 == pid) continue; - sprintf(full_path, "%s/%ld/%s", PROC_DIR, pid, COMM_FILE); + snprintf(full_path, sizeof(full_path), "%s/%ld/%s", PROC_DIR, pid, COMM_FILE); FILE *proc_name_file = fopen(full_path, "r"); if (NULL == proc_name_file) continue;