From b99e7124e8d620ed73afa96f1e463fc7a2b12778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?fengbojiang=28=E5=A7=9C=E5=87=A4=E6=B3=A2=29?= Date: Thu, 31 Oct 2019 15:58:26 +0800 Subject: [PATCH] Fixed #426, F-stack compile error in Red Hat 8.0 with gcc 8.2.1. --- ...Launch_F-Stack_on_AWS_EC2_in_one_minute.md | 2 +- lib/ff_config.c | 64 +++++++++++-------- lib/ff_ini_parser.c | 2 +- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/doc/Launch_F-Stack_on_AWS_EC2_in_one_minute.md b/doc/Launch_F-Stack_on_AWS_EC2_in_one_minute.md index 4c95deb04..a50d04751 100644 --- a/doc/Launch_F-Stack_on_AWS_EC2_in_one_minute.md +++ b/doc/Launch_F-Stack_on_AWS_EC2_in_one_minute.md @@ -3,7 +3,7 @@ If you have a Redhat7.3 EC2 instanceļ¼Œand then execute the following cmds, you will get the F-Stack server in one minute sudo -i - yum install -y git gcc openssl-devel kernel-devel-$(uname -r) bc numactl-devel mkdir make net-tools vim pciutils iproute pcre-devel zlib-devel + yum install -y git gcc openssl-devel kernel-devel-$(uname -r) bc numactl-devel mkdir make net-tools vim pciutils iproute pcre-devel zlib-devel elfutils-libelf-devel vim mkdir /data/f-stack git clone https://github.com/F-Stack/f-stack.git /data/f-stack diff --git a/lib/ff_config.c b/lib/ff_config.c index 1941c506a..12b1e19ec 100644 --- a/lib/ff_config.c +++ b/lib/ff_config.c @@ -117,8 +117,9 @@ parse_lcore_mask(struct ff_config *cfg, const char *coremask) zero_num = idx >> 2; shift = idx & 0x3; memset(zero,'0',zero_num); - sprintf(buf, "%llx%s", (unsigned long long)1<dpdk.proc_mask = strdup(buf); + snprintf(buf, sizeof(buf) - 1, "%llx%s", + (unsigned long long)1<dpdk.proc_mask = strdup(buf); } count++; } @@ -260,7 +261,7 @@ __parse_config_list(uint16_t *arr, int *sz, const char *value) { int nr_ele = 0; int max_ele = *sz; - strncpy(input, value, 4096); + strncpy(input, value, sizeof(input) - 1); nTokens = rte_strsplit(input, sizeof(input), tokens, 128, ','); for (i = 0; i < nTokens; i++) { char *tok = tokens[i]; @@ -622,7 +623,7 @@ dpdk_args_setup(struct ff_config *cfg) { int n = 0, i; dpdk_argv[n++] = strdup("f-stack"); - char temp[DPDK_CONFIG_MAXLEN] = {0}; + char temp[DPDK_CONFIG_MAXLEN] = {0}, temp2[DPDK_CONFIG_MAXLEN] = {0}; if (cfg->dpdk.no_huge) { dpdk_argv[n++] = strdup("--no-huge"); @@ -654,20 +655,24 @@ dpdk_args_setup(struct ff_config *cfg) cfg->dpdk.vdev_cfgs[i].vdev_id, cfg->dpdk.vdev_cfgs[i].path); if (cfg->dpdk.vdev_cfgs[i].nb_queues) { - sprintf(temp, "%s,queues=%u", - temp, cfg->dpdk.vdev_cfgs[i].nb_queues); + sprintf(temp2, ",queues=%u", + cfg->dpdk.vdev_cfgs[i].nb_queues); + strcat(temp, temp2); } if (cfg->dpdk.vdev_cfgs[i].nb_cq) { - sprintf(temp, "%s,cq=%u", - temp, cfg->dpdk.vdev_cfgs[i].nb_cq); + sprintf(temp2, ",cq=%u", + cfg->dpdk.vdev_cfgs[i].nb_cq); + strcat(temp, temp2); } if (cfg->dpdk.vdev_cfgs[i].queue_size) { - sprintf(temp, "%s,queue_size=%u", - temp, cfg->dpdk.vdev_cfgs[i].queue_size); + sprintf(temp2, ",queue_size=%u", + cfg->dpdk.vdev_cfgs[i].queue_size); + strcat(temp, temp2); } if (cfg->dpdk.vdev_cfgs[i].mac) { - sprintf(temp, "%s,mac=%s", - temp, cfg->dpdk.vdev_cfgs[i].mac); + sprintf(temp2, ",mac=%s", + cfg->dpdk.vdev_cfgs[i].mac); + strcat(temp, temp2); } dpdk_argv[n++] = strdup(temp); } @@ -687,38 +692,45 @@ dpdk_args_setup(struct ff_config *cfg) cfg->dpdk.bond_cfgs[i].slave); if (cfg->dpdk.bond_cfgs[i].primary) { - sprintf(temp, "%s,primary=%s", - temp, cfg->dpdk.bond_cfgs[i].primary); + sprintf(temp2, ",primary=%s", + cfg->dpdk.bond_cfgs[i].primary); + strcat(temp, temp2); } if (cfg->dpdk.bond_cfgs[i].socket_id) { - sprintf(temp, "%s,socket_id=%d", - temp, cfg->dpdk.bond_cfgs[i].socket_id); + sprintf(temp2, ",socket_id=%d", + cfg->dpdk.bond_cfgs[i].socket_id); + strcat(temp, temp2); } if (cfg->dpdk.bond_cfgs[i].bond_mac) { - sprintf(temp, "%s,mac=%s", - temp, cfg->dpdk.bond_cfgs[i].bond_mac); + sprintf(temp2, ",mac=%s", + cfg->dpdk.bond_cfgs[i].bond_mac); + strcat(temp, temp2); } if (cfg->dpdk.bond_cfgs[i].xmit_policy) { - sprintf(temp, "%s,xmit_policy=%s", - temp, cfg->dpdk.bond_cfgs[i].xmit_policy); + sprintf(temp2, ",xmit_policy=%s", + cfg->dpdk.bond_cfgs[i].xmit_policy); + strcat(temp, temp2); } if (cfg->dpdk.bond_cfgs[i].lsc_poll_period_ms) { - sprintf(temp, "%s,lsc_poll_period_ms=%d", - temp, cfg->dpdk.bond_cfgs[i].lsc_poll_period_ms); + sprintf(temp2, ",lsc_poll_period_ms=%d", + cfg->dpdk.bond_cfgs[i].lsc_poll_period_ms); + strcat(temp, temp2); } if (cfg->dpdk.bond_cfgs[i].up_delay) { - sprintf(temp, "%s,up_delay=%d", - temp, cfg->dpdk.bond_cfgs[i].up_delay); + sprintf(temp2, ",up_delay=%d", + cfg->dpdk.bond_cfgs[i].up_delay); + strcat(temp, temp2); } if (cfg->dpdk.bond_cfgs[i].down_delay) { - sprintf(temp, "%s,down_delay=%d", - temp, cfg->dpdk.bond_cfgs[i].down_delay); + sprintf(temp2, ",down_delay=%d", + cfg->dpdk.bond_cfgs[i].down_delay); + strcat(temp, temp2); } dpdk_argv[n++] = strdup(temp); } diff --git a/lib/ff_ini_parser.c b/lib/ff_ini_parser.c index 35f5390cc..2f2093e04 100644 --- a/lib/ff_ini_parser.c +++ b/lib/ff_ini_parser.c @@ -64,7 +64,7 @@ static char* find_chars_or_comment(const char* s, const char* chars) /* Version of strncpy that ensures dest (size bytes) is null-terminated. */ static char* strncpy0(char* dest, const char* src, size_t size) { - strncpy(dest, src, size); + strncpy(dest, src, size - 1); dest[size - 1] = '\0'; return dest; }