From f3b1fe0f1a418c60ac7611ae60730755a6243639 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 30 Jan 2018 15:19:26 +0100 Subject: [PATCH] update for null-termination of strings fix --- lib/src/phy/phch/test/pdsch_test.c | 2 +- srsenb/src/enb_cfg_parser.cc | 2 +- srsue/src/upper/gw.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/phy/phch/test/pdsch_test.c b/lib/src/phy/phch/test/pdsch_test.c index 3e4aa5abc..4053176d9 100644 --- a/lib/src/phy/phch/test/pdsch_test.c +++ b/lib/src/phy/phch/test/pdsch_test.c @@ -111,7 +111,7 @@ void parse_args(int argc, char **argv) { cfi = atoi(argv[optind]); break; case 'x': - strncpy(mimo_type_str, argv[optind], sizeof(mimo_type_str)); + strncpy(mimo_type_str, argv[optind], sizeof(mimo_type_str)-1); mimo_type_str[sizeof(mimo_type_str)-1] = 0; break; case 'p': diff --git a/srsenb/src/enb_cfg_parser.cc b/srsenb/src/enb_cfg_parser.cc index 6438a342e..ab25d9dcc 100644 --- a/srsenb/src/enb_cfg_parser.cc +++ b/srsenb/src/enb_cfg_parser.cc @@ -715,7 +715,7 @@ int enb::parse_sib9(std::string filename, LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_9_STRUC if (!parser::parse_section(filename, &sib9)) { data->hnb_name_present = true; if (name_enabled) { - strncpy((char*) data->hnb_name, hnb_name.c_str(), 48); + strncpy((char*) data->hnb_name, hnb_name.c_str(), 47); data->hnb_name[47] = 0; data->hnb_name_size = strnlen(hnb_name.c_str(), 48); } else if (hex_enabled) { diff --git a/srsue/src/upper/gw.cc b/srsue/src/upper/gw.cc index 5bc94d3e7..65748f57b 100644 --- a/srsue/src/upper/gw.cc +++ b/srsue/src/upper/gw.cc @@ -201,7 +201,7 @@ srslte::error_t gw::init_if(char *err_str) } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TUN | IFF_NO_PI; - strncpy(ifr.ifr_ifrn.ifrn_name, dev, IFNAMSIZ); + strncpy(ifr.ifr_ifrn.ifrn_name, dev, IFNAMSIZ-1); ifr.ifr_ifrn.ifrn_name[IFNAMSIZ-1] = 0; if(0 > ioctl(tun_fd, TUNSETIFF, &ifr)) {