* [PATCH 0/3] examples: format truncation bugs
@ 2025-11-10 18:19 Stephen Hemminger
2025-11-10 18:19 ` [PATCH 1/3] examples/server_node_efd: fix format overflow Stephen Hemminger
` (6 more replies)
0 siblings, 7 replies; 40+ messages in thread
From: Stephen Hemminger @ 2025-11-10 18:19 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
Enable format-overflow warnings in examples and fix the bugs.
Stephen Hemminger (3):
examples/server_node_efd: fix format overflow
examples/vdpa: fix format overflow warning
examples: re-enable format truncation warning
examples/meson.build | 5 ++---
examples/server_node_efd/efd_server/main.c | 2 +-
examples/vdpa/main.c | 12 ++++++------
3 files changed, 9 insertions(+), 10 deletions(-)
--
2.51.0
^ permalink raw reply [flat|nested] 40+ messages in thread* [PATCH 1/3] examples/server_node_efd: fix format overflow 2025-11-10 18:19 [PATCH 0/3] examples: format truncation bugs Stephen Hemminger @ 2025-11-10 18:19 ` Stephen Hemminger 2025-11-10 18:19 ` [PATCH 2/3] examples/vdpa: fix format overflow warning Stephen Hemminger ` (5 subsequent siblings) 6 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-10 18:19 UTC (permalink / raw) To: dev Cc: Stephen Hemminger, stable, Byron Marohn, Yipeng Wang, Pablo de Lara, Saikrishna Edupuganti, Christian Maciocco If format-truncation is enabled, the compiler detects a string overflow since the snprintf() is putting ethernet address and new line in buffer only sized for the address. Fixes: 39aad0e88c58 ("examples/flow_distributor: new example to demonstrate EFD") Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- examples/server_node_efd/efd_server/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/server_node_efd/efd_server/main.c b/examples/server_node_efd/efd_server/main.c index 75ff0ea532..62c3f4a16d 100644 --- a/examples/server_node_efd/efd_server/main.c +++ b/examples/server_node_efd/efd_server/main.c @@ -68,7 +68,7 @@ static const char * get_printable_mac_addr(uint16_t port) { static const char err_address[] = "00:00:00:00:00:00"; - static char addresses[RTE_MAX_ETHPORTS][sizeof(err_address)]; + static char addresses[RTE_MAX_ETHPORTS][RTE_ETHER_ADDR_FMT_SIZE + 1]; struct rte_ether_addr mac; int ret; -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH 2/3] examples/vdpa: fix format overflow warning 2025-11-10 18:19 [PATCH 0/3] examples: format truncation bugs Stephen Hemminger 2025-11-10 18:19 ` [PATCH 1/3] examples/server_node_efd: fix format overflow Stephen Hemminger @ 2025-11-10 18:19 ` Stephen Hemminger 2025-11-10 18:19 ` [PATCH 3/3] examples: re-enable format truncation warning Stephen Hemminger ` (4 subsequent siblings) 6 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-10 18:19 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, maxime.coquelin, stable, Chenbo Xia, Adrian Moreno The ifname is limited to 128 characters, but it would allow up to 128 characters as prefix then could overflow creating ifname. Change to limit path prefix to 124 (128 - sizeof("1024")) to avoid possible format overflow Fixes: 38f8ab0bbc8d ("vhost: make vDPA framework bus agnostic") Cc: maxime.coquelin@redhat.com Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- examples/vdpa/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index 289db26498..bdf751ad63 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -22,6 +22,8 @@ #define MAX_PATH_LEN 128 #define MAX_VDPA_SAMPLE_PORTS 1024 +#define stringify(x) (#x) +#define MAX_VDPA_STR_LEN sizeof(stringify(MAX_VDPA_SAMPLE_PORTS)) #define RTE_LOGTYPE_VDPA RTE_LOGTYPE_USER1 struct vdpa_port { @@ -36,7 +38,7 @@ struct vdpa_port { static struct vdpa_port vports[MAX_VDPA_SAMPLE_PORTS]; -static char iface[MAX_PATH_LEN]; +static char iface[MAX_PATH_LEN - MAX_VDPA_STR_LEN]; static int devcnt; static int interactive; static int client_mode; @@ -74,9 +76,8 @@ parse_args(int argc, char **argv) break; /* long options */ case 0: - if (strncmp(long_option[idx].name, "iface", - MAX_PATH_LEN) == 0) { - rte_strscpy(iface, optarg, MAX_PATH_LEN); + if (!strcmp(long_option[idx].name, "iface")) { + rte_strscpy(iface, optarg, sizeof(iface)); printf("iface %s\n", iface); } if (!strcmp(long_option[idx].name, "interactive")) { -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH 3/3] examples: re-enable format truncation warning 2025-11-10 18:19 [PATCH 0/3] examples: format truncation bugs Stephen Hemminger 2025-11-10 18:19 ` [PATCH 1/3] examples/server_node_efd: fix format overflow Stephen Hemminger 2025-11-10 18:19 ` [PATCH 2/3] examples/vdpa: fix format overflow warning Stephen Hemminger @ 2025-11-10 18:19 ` Stephen Hemminger 2025-11-11 22:17 ` [PATCH v2 0/7] fix format-truncation warnings Stephen Hemminger ` (3 subsequent siblings) 6 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-10 18:19 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger There were several hidden bugs in examples because format truncation warning was disabled. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- examples/meson.build | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/meson.build b/examples/meson.build index 8e8968a1fa..25d9c88457 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -78,10 +78,9 @@ else examples = get_option('examples').split(',') allow_skips = false # error out if we can't build a requested app endif + default_cflags = machine_args -if cc.has_argument('-Wno-format-truncation') - default_cflags += '-Wno-format-truncation' -endif + default_ldflags = dpdk_extra_ldflags if get_option('default_library') == 'static' and not is_windows default_ldflags += ['-Wl,--export-dynamic'] -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v2 0/7] fix format-truncation warnings 2025-11-10 18:19 [PATCH 0/3] examples: format truncation bugs Stephen Hemminger ` (2 preceding siblings ...) 2025-11-10 18:19 ` [PATCH 3/3] examples: re-enable format truncation warning Stephen Hemminger @ 2025-11-11 22:17 ` Stephen Hemminger 2025-11-11 22:17 ` [PATCH v2 1/7] examples/server_node_efd: fix format overflow Stephen Hemminger ` (6 more replies) 2025-11-15 19:36 ` [PATCH v3 0/4] examples: fix " Stephen Hemminger ` (2 subsequent siblings) 6 siblings, 7 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-11 22:17 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger Enable and fix format-truncation warnings in examples and tests. v2 - fix build warnings (more fixes needed) - do test as well (could be separate series?) Stephen Hemminger (7): examples/server_node_efd: fix format overflow examples/vdpa: fix format overflow warning examples/ip_reassembly: add check before formatting name examples: re-enable format truncation warning test: refactor file prefix arg handling test: increase size of memzone name test: re-enable format-truncation warnings app/test/meson.build | 1 - app/test/test_eal_flags.c | 161 ++++++++------------- app/test/test_memzone.c | 2 +- examples/ip_reassembly/main.c | 7 + examples/meson.build | 5 +- examples/server_node_efd/efd_server/main.c | 2 +- examples/server_node_efd/shared/common.h | 3 +- examples/vdpa/main.c | 9 +- 8 files changed, 77 insertions(+), 113 deletions(-) -- 2.51.0 ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH v2 1/7] examples/server_node_efd: fix format overflow 2025-11-11 22:17 ` [PATCH v2 0/7] fix format-truncation warnings Stephen Hemminger @ 2025-11-11 22:17 ` Stephen Hemminger 2025-11-11 22:17 ` [PATCH v2 2/7] examples/vdpa: fix format overflow warning Stephen Hemminger ` (5 subsequent siblings) 6 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-11 22:17 UTC (permalink / raw) To: dev Cc: Stephen Hemminger, stable, Byron Marohn, Yipeng Wang, Saikrishna Edupuganti, Pablo de Lara, Christian Maciocco If format-truncation is enabled, the compiler detects a string overflow since the snprintf() is putting ethernet address and new line in buffer only sized for the address. Since get_rx_queue_name() is used to create a ring name. The buffer should be sized to be a valid ring name. This fixes some format-overflow warnings and also corrects for future errors. Fixes: 39aad0e88c58 ("examples/flow_distributor: new example to demonstrate EFD") Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- examples/server_node_efd/efd_server/main.c | 2 +- examples/server_node_efd/shared/common.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/server_node_efd/efd_server/main.c b/examples/server_node_efd/efd_server/main.c index 75ff0ea532..62c3f4a16d 100644 --- a/examples/server_node_efd/efd_server/main.c +++ b/examples/server_node_efd/efd_server/main.c @@ -68,7 +68,7 @@ static const char * get_printable_mac_addr(uint16_t port) { static const char err_address[] = "00:00:00:00:00:00"; - static char addresses[RTE_MAX_ETHPORTS][sizeof(err_address)]; + static char addresses[RTE_MAX_ETHPORTS][RTE_ETHER_ADDR_FMT_SIZE + 1]; struct rte_ether_addr mac; int ret; diff --git a/examples/server_node_efd/shared/common.h b/examples/server_node_efd/shared/common.h index e1ab7e62b7..6726e2031e 100644 --- a/examples/server_node_efd/shared/common.h +++ b/examples/server_node_efd/shared/common.h @@ -58,8 +58,9 @@ get_rx_queue_name(unsigned int id) /* * Buffer for return value. Size calculated by %u being replaced * by maximum 3 digits (plus an extra byte for safety) + * Used as ring name, so upper limit is ring name size. */ - static char buffer[sizeof(MP_NODE_RXQ_NAME) + 2]; + static char buffer[RTE_RING_NAMESIZE]; snprintf(buffer, sizeof(buffer), MP_NODE_RXQ_NAME, id); return buffer; -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v2 2/7] examples/vdpa: fix format overflow warning 2025-11-11 22:17 ` [PATCH v2 0/7] fix format-truncation warnings Stephen Hemminger 2025-11-11 22:17 ` [PATCH v2 1/7] examples/server_node_efd: fix format overflow Stephen Hemminger @ 2025-11-11 22:17 ` Stephen Hemminger 2025-11-14 15:59 ` Bruce Richardson 2025-11-11 22:17 ` [PATCH v2 3/7] examples/ip_reassembly: add check before formatting name Stephen Hemminger ` (4 subsequent siblings) 6 siblings, 1 reply; 40+ messages in thread From: Stephen Hemminger @ 2025-11-11 22:17 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, maxime.coquelin, stable, Chenbo Xia, Adrian Moreno The ifname is limited to 128 characters, but it would allow up to 128 characters as prefix then could overflow creating ifname. Change to limit path prefix to 124 (128 - sizeof("1024")) to avoid possible format overflow Fixes: 38f8ab0bbc8d ("vhost: make vDPA framework bus agnostic") Cc: maxime.coquelin@redhat.com Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- examples/vdpa/main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index 289db26498..7fd0e55b20 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -22,6 +22,8 @@ #define MAX_PATH_LEN 128 #define MAX_VDPA_SAMPLE_PORTS 1024 +#define stringify(x) (#x) +#define MAX_VDPA_STR_LEN sizeof(stringify(MAX_VDPA_SAMPLE_PORTS)) #define RTE_LOGTYPE_VDPA RTE_LOGTYPE_USER1 struct vdpa_port { @@ -36,7 +38,7 @@ struct vdpa_port { static struct vdpa_port vports[MAX_VDPA_SAMPLE_PORTS]; -static char iface[MAX_PATH_LEN]; +static char iface[MAX_PATH_LEN - MAX_VDPA_STR_LEN]; static int devcnt; static int interactive; static int client_mode; @@ -74,9 +76,8 @@ parse_args(int argc, char **argv) break; /* long options */ case 0: - if (strncmp(long_option[idx].name, "iface", - MAX_PATH_LEN) == 0) { - rte_strscpy(iface, optarg, MAX_PATH_LEN); + if (!strcmp(long_option[idx].name, "iface")) { + rte_strscpy(iface, optarg, sizeof(iface)); printf("iface %s\n", iface); } if (!strcmp(long_option[idx].name, "interactive")) { -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* Re: [PATCH v2 2/7] examples/vdpa: fix format overflow warning 2025-11-11 22:17 ` [PATCH v2 2/7] examples/vdpa: fix format overflow warning Stephen Hemminger @ 2025-11-14 15:59 ` Bruce Richardson 0 siblings, 0 replies; 40+ messages in thread From: Bruce Richardson @ 2025-11-14 15:59 UTC (permalink / raw) To: Stephen Hemminger; +Cc: dev, maxime.coquelin, stable, Chenbo Xia, Adrian Moreno On Tue, Nov 11, 2025 at 02:17:19PM -0800, Stephen Hemminger wrote: > The ifname is limited to 128 characters, but it would allow up > to 128 characters as prefix then could overflow creating ifname. > > Change to limit path prefix to 124 (128 - sizeof("1024")) nit: sizeof("1024") == 5, because of the \0. > to avoid possible format overflow > > Fixes: 38f8ab0bbc8d ("vhost: make vDPA framework bus agnostic") > Cc: maxime.coquelin@redhat.com > Cc: stable@dpdk.org > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> I assume this was found by enabling compiler warnings. It would be good to include the actual warning message in the commit log, given that the patch doesn't actually modify the line at which the overflow occurs. Acked-by: Bruce Richardson <bruce.richardson@intel.com> > --- > examples/vdpa/main.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c > index 289db26498..7fd0e55b20 100644 > --- a/examples/vdpa/main.c > +++ b/examples/vdpa/main.c > @@ -22,6 +22,8 @@ > > #define MAX_PATH_LEN 128 > #define MAX_VDPA_SAMPLE_PORTS 1024 > +#define stringify(x) (#x) > +#define MAX_VDPA_STR_LEN sizeof(stringify(MAX_VDPA_SAMPLE_PORTS)) We have RTE_STR() and _RTE_STR() in rte_common.h > #define RTE_LOGTYPE_VDPA RTE_LOGTYPE_USER1 > > struct vdpa_port { > @@ -36,7 +38,7 @@ struct vdpa_port { > > static struct vdpa_port vports[MAX_VDPA_SAMPLE_PORTS]; > > -static char iface[MAX_PATH_LEN]; > +static char iface[MAX_PATH_LEN - MAX_VDPA_STR_LEN]; > static int devcnt; > static int interactive; > static int client_mode; > @@ -74,9 +76,8 @@ parse_args(int argc, char **argv) > break; > /* long options */ > case 0: > - if (strncmp(long_option[idx].name, "iface", > - MAX_PATH_LEN) == 0) { > - rte_strscpy(iface, optarg, MAX_PATH_LEN); > + if (!strcmp(long_option[idx].name, "iface")) { > + rte_strscpy(iface, optarg, sizeof(iface)); I realise that the rte_strscpy function is what was here before, but given that we are not checking the return value, there is no reason to choose the dpdk-only strscpy function over the more-standard strlcpy. > printf("iface %s\n", iface); > } > if (!strcmp(long_option[idx].name, "interactive")) { > -- > 2.51.0 > ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH v2 3/7] examples/ip_reassembly: add check before formatting name 2025-11-11 22:17 ` [PATCH v2 0/7] fix format-truncation warnings Stephen Hemminger 2025-11-11 22:17 ` [PATCH v2 1/7] examples/server_node_efd: fix format overflow Stephen Hemminger 2025-11-11 22:17 ` [PATCH v2 2/7] examples/vdpa: fix format overflow warning Stephen Hemminger @ 2025-11-11 22:17 ` Stephen Hemminger 2025-11-12 14:50 ` Konstantin Ananyev 2025-11-14 16:05 ` Bruce Richardson 2025-11-11 22:17 ` [PATCH v2 4/7] examples: re-enable format truncation warning Stephen Hemminger ` (3 subsequent siblings) 6 siblings, 2 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-11 22:17 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, Konstantin Ananyev In theory, lcore and queue could be so large that mbuf pool name could overflow. But that can never happen since lcore and queue will be in range. Add a check so that static tools know that. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- examples/ip_reassembly/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/ip_reassembly/main.c b/examples/ip_reassembly/main.c index 17ae76d4ba..25b904dbd4 100644 --- a/examples/ip_reassembly/main.c +++ b/examples/ip_reassembly/main.c @@ -884,6 +884,13 @@ setup_queue_tbl(struct rx_queue *rxq, uint32_t lcore, uint32_t queue) nb_mbuf = RTE_MAX(nb_mbuf, (uint32_t)NB_MBUF); + /* Should never happen but check so that pool name won't be too long. */ + if (lcore > RTE_MAX_LCORE || queue > RTE_MAX_QUEUES_PER_PORT) { + RTE_LOG(ERR, IP_RSMBL, "invalid lcore %u or queue %u", + lcore, queue); + return -1; + } + snprintf(buf, sizeof(buf), "mbuf_pool_%u_%u", lcore, queue); rxq->pool = rte_pktmbuf_pool_create(buf, nb_mbuf, MEMPOOL_CACHE_SIZE, 0, -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* RE: [PATCH v2 3/7] examples/ip_reassembly: add check before formatting name 2025-11-11 22:17 ` [PATCH v2 3/7] examples/ip_reassembly: add check before formatting name Stephen Hemminger @ 2025-11-12 14:50 ` Konstantin Ananyev 2025-11-14 16:05 ` Bruce Richardson 1 sibling, 0 replies; 40+ messages in thread From: Konstantin Ananyev @ 2025-11-12 14:50 UTC (permalink / raw) To: Stephen Hemminger, dev@dpdk.org > > In theory, lcore and queue could be so large that mbuf pool name > could overflow. But that can never happen since lcore and queue > will be in range. Add a check so that static tools know that. > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> > --- > examples/ip_reassembly/main.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/examples/ip_reassembly/main.c b/examples/ip_reassembly/main.c > index 17ae76d4ba..25b904dbd4 100644 > --- a/examples/ip_reassembly/main.c > +++ b/examples/ip_reassembly/main.c > @@ -884,6 +884,13 @@ setup_queue_tbl(struct rx_queue *rxq, uint32_t lcore, > uint32_t queue) > > nb_mbuf = RTE_MAX(nb_mbuf, (uint32_t)NB_MBUF); > > + /* Should never happen but check so that pool name won't be too long. */ > + if (lcore > RTE_MAX_LCORE || queue > RTE_MAX_QUEUES_PER_PORT) { > + RTE_LOG(ERR, IP_RSMBL, "invalid lcore %u or queue %u", > + lcore, queue); > + return -1; > + } > + > snprintf(buf, sizeof(buf), "mbuf_pool_%u_%u", lcore, queue); > > rxq->pool = rte_pktmbuf_pool_create(buf, nb_mbuf, > MEMPOOL_CACHE_SIZE, 0, > -- Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com> > 2.51.0 ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v2 3/7] examples/ip_reassembly: add check before formatting name 2025-11-11 22:17 ` [PATCH v2 3/7] examples/ip_reassembly: add check before formatting name Stephen Hemminger 2025-11-12 14:50 ` Konstantin Ananyev @ 2025-11-14 16:05 ` Bruce Richardson 1 sibling, 0 replies; 40+ messages in thread From: Bruce Richardson @ 2025-11-14 16:05 UTC (permalink / raw) To: Stephen Hemminger; +Cc: dev, Konstantin Ananyev On Tue, Nov 11, 2025 at 02:17:20PM -0800, Stephen Hemminger wrote: > In theory, lcore and queue could be so large that mbuf pool name > could overflow. But that can never happen since lcore and queue > will be in range. Add a check so that static tools know that. > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> > --- Again, maybe include the warning omitted by the compiler Acked-by: Bruce Richardson <bruce.richardson@intel.com> > examples/ip_reassembly/main.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/examples/ip_reassembly/main.c b/examples/ip_reassembly/main.c > index 17ae76d4ba..25b904dbd4 100644 > --- a/examples/ip_reassembly/main.c > +++ b/examples/ip_reassembly/main.c > @@ -884,6 +884,13 @@ setup_queue_tbl(struct rx_queue *rxq, uint32_t lcore, uint32_t queue) > > nb_mbuf = RTE_MAX(nb_mbuf, (uint32_t)NB_MBUF); > > + /* Should never happen but check so that pool name won't be too long. */ > + if (lcore > RTE_MAX_LCORE || queue > RTE_MAX_QUEUES_PER_PORT) { > + RTE_LOG(ERR, IP_RSMBL, "invalid lcore %u or queue %u", > + lcore, queue); > + return -1; > + } > + > snprintf(buf, sizeof(buf), "mbuf_pool_%u_%u", lcore, queue); > > rxq->pool = rte_pktmbuf_pool_create(buf, nb_mbuf, MEMPOOL_CACHE_SIZE, 0, > -- > 2.51.0 > ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH v2 4/7] examples: re-enable format truncation warning 2025-11-11 22:17 ` [PATCH v2 0/7] fix format-truncation warnings Stephen Hemminger ` (2 preceding siblings ...) 2025-11-11 22:17 ` [PATCH v2 3/7] examples/ip_reassembly: add check before formatting name Stephen Hemminger @ 2025-11-11 22:17 ` Stephen Hemminger 2025-11-14 16:07 ` Bruce Richardson 2025-11-11 22:17 ` [PATCH v2 5/7] test: refactor file prefix arg handling Stephen Hemminger ` (2 subsequent siblings) 6 siblings, 1 reply; 40+ messages in thread From: Stephen Hemminger @ 2025-11-11 22:17 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger There were several hidden bugs in examples because format truncation warning was disabled. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- examples/meson.build | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/meson.build b/examples/meson.build index 8e8968a1fa..25d9c88457 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -78,10 +78,9 @@ else examples = get_option('examples').split(',') allow_skips = false # error out if we can't build a requested app endif + default_cflags = machine_args -if cc.has_argument('-Wno-format-truncation') - default_cflags += '-Wno-format-truncation' -endif + default_ldflags = dpdk_extra_ldflags if get_option('default_library') == 'static' and not is_windows default_ldflags += ['-Wl,--export-dynamic'] -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* Re: [PATCH v2 4/7] examples: re-enable format truncation warning 2025-11-11 22:17 ` [PATCH v2 4/7] examples: re-enable format truncation warning Stephen Hemminger @ 2025-11-14 16:07 ` Bruce Richardson 0 siblings, 0 replies; 40+ messages in thread From: Bruce Richardson @ 2025-11-14 16:07 UTC (permalink / raw) To: Stephen Hemminger; +Cc: dev On Tue, Nov 11, 2025 at 02:17:21PM -0800, Stephen Hemminger wrote: > There were several hidden bugs in examples because format > truncation warning was disabled. > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> > --- Acked-by: Bruce Richardson <bruce.richardson@intel.com> > examples/meson.build | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/examples/meson.build b/examples/meson.build > index 8e8968a1fa..25d9c88457 100644 > --- a/examples/meson.build > +++ b/examples/meson.build > @@ -78,10 +78,9 @@ else > examples = get_option('examples').split(',') > allow_skips = false # error out if we can't build a requested app > endif > + > default_cflags = machine_args > -if cc.has_argument('-Wno-format-truncation') > - default_cflags += '-Wno-format-truncation' > -endif > + > default_ldflags = dpdk_extra_ldflags > if get_option('default_library') == 'static' and not is_windows > default_ldflags += ['-Wl,--export-dynamic'] > -- > 2.51.0 > ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH v2 5/7] test: refactor file prefix arg handling 2025-11-11 22:17 ` [PATCH v2 0/7] fix format-truncation warnings Stephen Hemminger ` (3 preceding siblings ...) 2025-11-11 22:17 ` [PATCH v2 4/7] examples: re-enable format truncation warning Stephen Hemminger @ 2025-11-11 22:17 ` Stephen Hemminger 2025-11-11 22:17 ` [PATCH v2 6/7] test: increase size of memzone name Stephen Hemminger 2025-11-11 22:17 ` [PATCH v2 7/7] test: re-enable format-truncation warnings Stephen Hemminger 6 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-11 22:17 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, Tyler Retzlaff Make setting up --file-prefix arg logic into a function, and avoid impossible case of file prefix path causing overflow of string. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- app/test/test_eal_flags.c | 161 ++++++++++++++------------------------ 1 file changed, 59 insertions(+), 102 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index e32f83d3c8..05b4135a51 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -121,6 +121,8 @@ test_misc_flags(void) #define no_shconf "--no-shconf" #define allow "--allow" #define vdev "--vdev" +#define file_prefix "--file-prefix" + #define memtest "memtest" #define memtest1 "memtest1" #define memtest2 "memtest2" @@ -312,26 +314,40 @@ get_number_of_sockets(void) } #endif -/* - * Test that the app doesn't run with invalid allow option. - * Final tests ensures it does run with valid options as sanity check (one - * test for with Domain+BDF, second for just with BDF) - */ +/* Get the file_prefix xommand line argument */ static int -test_allow_flag(void) +get_file_prefix(char *prefix, size_t size) { - unsigned i; #ifdef RTE_EXEC_ENV_FREEBSD /* BSD target doesn't support prefixes at this point */ - const char * prefix = ""; + RTE_SET_USED(len); + *prefix = 0; + return 0; #else - char prefix[PATH_MAX], tmp[PATH_MAX]; + char tmp[PATH_MAX]; + if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { printf("Error - unable to get current prefix!\n"); return -1; } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); + snprintf(prefix, size, "%s=%s", file_prefix, tmp); + return 0; #endif +} + +/* + * Test that the app doesn't run with invalid allow option. + * Final tests ensures it does run with valid options as sanity check (one + * test for with Domain+BDF, second for just with BDF) + */ +static int +test_allow_flag(void) +{ + unsigned i; + char prefix[PATH_MAX + sizeof(file_prefix)]; + + if (get_file_prefix(prefix, sizeof(prefix)) != 0) + return TEST_FAILED; const char *wlinval[][7] = { {prgname, prefix, mp_flag, @@ -387,17 +403,10 @@ test_allow_flag(void) static int test_invalid_b_flag(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char * prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); - return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif + char prefix[PATH_MAX + sizeof(file_prefix)]; + + if (get_file_prefix(prefix, sizeof(prefix)) != 0) + return TEST_FAILED; const char *blinval[][5] = { {prgname, prefix, mp_flag, "-b", "error"}, @@ -491,17 +500,10 @@ test_invalid_vdev_flag(void) static int test_invalid_r_flag(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char * prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); - return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif + char prefix[PATH_MAX + sizeof(file_prefix)]; + + if (get_file_prefix(prefix, sizeof(prefix)) != 0) + return TEST_FAILED; const char *rinval[][5] = { {prgname, prefix, mp_flag, "-r", "error"}, @@ -535,17 +537,10 @@ test_invalid_r_flag(void) static int test_missing_c_flag(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char * prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); - return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif + char prefix[PATH_MAX + sizeof(file_prefix)]; + + if (get_file_prefix(prefix, sizeof(prefix)) != 0) + return TEST_FAILED; /* -c flag but no coremask value */ const char *argv1[] = { prgname, prefix, mp_flag, "-c"}; @@ -694,17 +689,10 @@ test_missing_c_flag(void) static int test_main_lcore_flag(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char *prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); - return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif + char prefix[PATH_MAX + sizeof(file_prefix)]; + + if (get_file_prefix(prefix, sizeof(prefix)) != 0) + return TEST_FAILED; if (!rte_lcore_is_enabled(0) || !rte_lcore_is_enabled(1)) return TEST_SKIPPED; @@ -751,17 +739,10 @@ test_main_lcore_flag(void) static int test_invalid_n_flag(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char * prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); - return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif + char prefix[PATH_MAX + sizeof(file_prefix)]; + + if (get_file_prefix(prefix, sizeof(prefix)) != 0) + return TEST_FAILED; /* -n flag but no value */ const char *argv1[] = { prgname, prefix, no_huge, no_shconf, @@ -803,18 +784,10 @@ test_invalid_n_flag(void) static int test_no_hpet_flag(void) { - char prefix[PATH_MAX] = ""; + char prefix[PATH_MAX + sizeof(file_prefix)]; -#ifdef RTE_EXEC_ENV_FREEBSD - return 0; -#else - char tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); - return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif + if (get_file_prefix(prefix, sizeof(prefix)) != 0) + return TEST_FAILED; /* With --no-hpet */ const char *argv1[] = {prgname, prefix, mp_flag, no_hpet}; @@ -913,17 +886,14 @@ test_misc_flags(void) const char * prefix = ""; const char * nosh_prefix = ""; #else - char prefix[PATH_MAX], tmp[PATH_MAX]; + char prefix[PATH_MAX + sizeof(file_prefix)]; const char * nosh_prefix = "--file-prefix=noshconf"; FILE * hugedir_handle = NULL; char line[PATH_MAX] = {0}; unsigned i, isempty = 1; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); - return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); + if (get_file_prefix(prefix, sizeof(prefix)) != 0) + return TEST_FAILED; /* * get first valid hugepage path @@ -1239,16 +1209,10 @@ test_file_prefix(void) * run in legacy mode, and not present at all after run in default * mem mode */ - char prefix[PATH_MAX] = ""; + char prefix[PATH_MAX + sizeof(file_prefix)]; -#ifdef RTE_EXEC_ENV_FREEBSD - return 0; -#else - if (get_current_prefix(prefix, sizeof(prefix)) == NULL) { - printf("Error - unable to get current prefix!\n"); - return -1; - } -#endif + if (get_file_prefix(prefix, sizeof(prefix)) != 0) + return TEST_FAILED; /* this should fail unless the test itself is run with "memtest" prefix */ const char *argv0[] = {prgname, mp_flag, "-m", @@ -1525,17 +1489,10 @@ populate_socket_mem_param(int num_sockets, const char *mem, static int test_memory_flags(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char * prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); - return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif + char prefix[PATH_MAX + sizeof(file_prefix)]; + + if (get_file_prefix(prefix, sizeof(prefix)) != 0) + return TEST_FAILED; /* valid -m flag and mp flag */ const char *argv0[] = {prgname, prefix, mp_flag, -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v2 6/7] test: increase size of memzone name 2025-11-11 22:17 ` [PATCH v2 0/7] fix format-truncation warnings Stephen Hemminger ` (4 preceding siblings ...) 2025-11-11 22:17 ` [PATCH v2 5/7] test: refactor file prefix arg handling Stephen Hemminger @ 2025-11-11 22:17 ` Stephen Hemminger 2025-11-14 16:07 ` Bruce Richardson 2025-11-11 22:17 ` [PATCH v2 7/7] test: re-enable format-truncation warnings Stephen Hemminger 6 siblings, 1 reply; 40+ messages in thread From: Stephen Hemminger @ 2025-11-11 22:17 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, Anatoly Burakov The tests were using a name buffer of 20 characters which could overflow if number of memory zones got large. The upper limit is defined as RTE_MEMZONE_NAMESIZE so use that. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- app/test/test_memzone.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test/test_memzone.c b/app/test/test_memzone.c index 506725ea41..6586dad18d 100644 --- a/app/test/test_memzone.c +++ b/app/test/test_memzone.c @@ -872,7 +872,7 @@ test_memzone_free(void) { const struct rte_memzone **mz; int i; - char name[20]; + char name[RTE_MEMZONE_NAMESIZE]; int rc = -1; mz = rte_calloc("memzone_test", rte_memzone_max_get() + 1, -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* Re: [PATCH v2 6/7] test: increase size of memzone name 2025-11-11 22:17 ` [PATCH v2 6/7] test: increase size of memzone name Stephen Hemminger @ 2025-11-14 16:07 ` Bruce Richardson 0 siblings, 0 replies; 40+ messages in thread From: Bruce Richardson @ 2025-11-14 16:07 UTC (permalink / raw) To: Stephen Hemminger; +Cc: dev, Anatoly Burakov On Tue, Nov 11, 2025 at 02:17:23PM -0800, Stephen Hemminger wrote: > The tests were using a name buffer of 20 characters which could > overflow if number of memory zones got large. The upper limit > is defined as RTE_MEMZONE_NAMESIZE so use that. > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Bruce Richardson <bruce.richardson@intel.com> > --- > app/test/test_memzone.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/app/test/test_memzone.c b/app/test/test_memzone.c > index 506725ea41..6586dad18d 100644 > --- a/app/test/test_memzone.c > +++ b/app/test/test_memzone.c > @@ -872,7 +872,7 @@ test_memzone_free(void) > { > const struct rte_memzone **mz; > int i; > - char name[20]; > + char name[RTE_MEMZONE_NAMESIZE]; > int rc = -1; > > mz = rte_calloc("memzone_test", rte_memzone_max_get() + 1, > -- > 2.51.0 > ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH v2 7/7] test: re-enable format-truncation warnings 2025-11-11 22:17 ` [PATCH v2 0/7] fix format-truncation warnings Stephen Hemminger ` (5 preceding siblings ...) 2025-11-11 22:17 ` [PATCH v2 6/7] test: increase size of memzone name Stephen Hemminger @ 2025-11-11 22:17 ` Stephen Hemminger 2025-11-14 16:08 ` Bruce Richardson 6 siblings, 1 reply; 40+ messages in thread From: Stephen Hemminger @ 2025-11-11 22:17 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger Tests should be built with warnings. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- app/test/meson.build | 1 - 1 file changed, 1 deletion(-) diff --git a/app/test/meson.build b/app/test/meson.build index 8df8d3edd1..66cbabe9fe 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -260,7 +260,6 @@ cflags += no_wvla_cflag extra_flags = [ # Strict-aliasing rules are violated by uint8_t[] to context size casts. '-fno-strict-aliasing', - '-Wno-format-truncation', ] foreach arg: extra_flags -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* Re: [PATCH v2 7/7] test: re-enable format-truncation warnings 2025-11-11 22:17 ` [PATCH v2 7/7] test: re-enable format-truncation warnings Stephen Hemminger @ 2025-11-14 16:08 ` Bruce Richardson 0 siblings, 0 replies; 40+ messages in thread From: Bruce Richardson @ 2025-11-14 16:08 UTC (permalink / raw) To: Stephen Hemminger; +Cc: dev On Tue, Nov 11, 2025 at 02:17:24PM -0800, Stephen Hemminger wrote: > Tests should be built with warnings. > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> > --- Acked-by: Bruce Richardson <bruce.richardson@intel.com> > app/test/meson.build | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/app/test/meson.build b/app/test/meson.build > index 8df8d3edd1..66cbabe9fe 100644 > --- a/app/test/meson.build > +++ b/app/test/meson.build > @@ -260,7 +260,6 @@ cflags += no_wvla_cflag > extra_flags = [ > # Strict-aliasing rules are violated by uint8_t[] to context size casts. > '-fno-strict-aliasing', > - '-Wno-format-truncation', > ] > > foreach arg: extra_flags > -- > 2.51.0 > ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH v3 0/4] examples: fix format-truncation warnings 2025-11-10 18:19 [PATCH 0/3] examples: format truncation bugs Stephen Hemminger ` (3 preceding siblings ...) 2025-11-11 22:17 ` [PATCH v2 0/7] fix format-truncation warnings Stephen Hemminger @ 2025-11-15 19:36 ` Stephen Hemminger 2025-11-15 19:36 ` [PATCH v3 1/4] examples/server_node_efd: fix format overflow Stephen Hemminger ` (3 more replies) 2025-11-20 16:21 ` [PATCH v4 0/4] examples: fix format-truncation errors Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 0/8] tests: fix format truncation warnings Stephen Hemminger 6 siblings, 4 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-15 19:36 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger Enable and fix format-truncation warnings in examples v3 - examples only, update commit messages Stephen Hemminger (4): examples/server_node_efd: fix format overflow examples/vdpa: fix format overflow warning examples/ip_reassembly: add check before formatting name examples: enable format truncation warning examples/ip_reassembly/main.c | 7 +++++++ examples/meson.build | 5 ++--- examples/server_node_efd/efd_server/main.c | 2 +- examples/server_node_efd/shared/common.h | 3 ++- examples/vdpa/main.c | 9 +++++---- 5 files changed, 17 insertions(+), 9 deletions(-) -- 2.51.0 ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH v3 1/4] examples/server_node_efd: fix format overflow 2025-11-15 19:36 ` [PATCH v3 0/4] examples: fix " Stephen Hemminger @ 2025-11-15 19:36 ` Stephen Hemminger 2025-11-17 8:50 ` Bruce Richardson 2025-11-15 19:36 ` [PATCH v3 2/4] examples/vdpa: fix format overflow warning Stephen Hemminger ` (2 subsequent siblings) 3 siblings, 1 reply; 40+ messages in thread From: Stephen Hemminger @ 2025-11-15 19:36 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, stable If format-truncation is enabled, the compiler detects a string overflow since the snprintf() is putting ethernet address and new line in buffer only sized for the address. Since get_rx_queue_name() is used to create a ring name. The buffer should be sized to be a valid ring name. This fixes some format-overflow warnings and also corrects for future errors. In file included from ../examples/server_node_efd/efd_server/main.c:31: In function ‘get_printable_mac_addr’, inlined from ‘do_stats_display’ at ../examples/server_node_efd/efd_server/main.c:136:3: ../lib/net/rte_ether.h:248:36: warning: ‘snprintf’ output truncated before the last format character [-Wformat-truncation=] 248 | #define RTE_ETHER_ADDR_PRT_FMT "%02X:%02X:%02X:%02X:%02X:%02X" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../examples/server_node_efd/efd_server/main.c:86:33: note: in expansion of macro ‘RTE_ETHER_ADDR_PRT_FMT’ 86 | RTE_ETHER_ADDR_PRT_FMT "\n", | ^~~~~~~~~~~~~~~~~~~~~~ ../examples/server_node_efd/efd_server/main.c: In function ‘do_stats_display’: ../examples/server_node_efd/efd_server/main.c:86:59: note: format string is defined here 86 | RTE_ETHER_ADDR_PRT_FMT "\n", | Fixes: 39aad0e88c58 ("examples/flow_distributor: new example to demonstrate EFD") Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- examples/server_node_efd/efd_server/main.c | 2 +- examples/server_node_efd/shared/common.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/server_node_efd/efd_server/main.c b/examples/server_node_efd/efd_server/main.c index 75ff0ea532..62c3f4a16d 100644 --- a/examples/server_node_efd/efd_server/main.c +++ b/examples/server_node_efd/efd_server/main.c @@ -68,7 +68,7 @@ static const char * get_printable_mac_addr(uint16_t port) { static const char err_address[] = "00:00:00:00:00:00"; - static char addresses[RTE_MAX_ETHPORTS][sizeof(err_address)]; + static char addresses[RTE_MAX_ETHPORTS][RTE_ETHER_ADDR_FMT_SIZE + 1]; struct rte_ether_addr mac; int ret; diff --git a/examples/server_node_efd/shared/common.h b/examples/server_node_efd/shared/common.h index e1ab7e62b7..6726e2031e 100644 --- a/examples/server_node_efd/shared/common.h +++ b/examples/server_node_efd/shared/common.h @@ -58,8 +58,9 @@ get_rx_queue_name(unsigned int id) /* * Buffer for return value. Size calculated by %u being replaced * by maximum 3 digits (plus an extra byte for safety) + * Used as ring name, so upper limit is ring name size. */ - static char buffer[sizeof(MP_NODE_RXQ_NAME) + 2]; + static char buffer[RTE_RING_NAMESIZE]; snprintf(buffer, sizeof(buffer), MP_NODE_RXQ_NAME, id); return buffer; -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* Re: [PATCH v3 1/4] examples/server_node_efd: fix format overflow 2025-11-15 19:36 ` [PATCH v3 1/4] examples/server_node_efd: fix format overflow Stephen Hemminger @ 2025-11-17 8:50 ` Bruce Richardson 0 siblings, 0 replies; 40+ messages in thread From: Bruce Richardson @ 2025-11-17 8:50 UTC (permalink / raw) To: Stephen Hemminger; +Cc: dev, stable On Sat, Nov 15, 2025 at 11:36:36AM -0800, Stephen Hemminger wrote: > If format-truncation is enabled, the compiler detects a string overflow > since the snprintf() is putting ethernet address and new line > in buffer only sized for the address. > > Since get_rx_queue_name() is used to create a ring name. > The buffer should be sized to be a valid ring name. > This fixes some format-overflow warnings and also corrects > for future errors. > > In file included from ../examples/server_node_efd/efd_server/main.c:31: > In function ‘get_printable_mac_addr’, > inlined from ‘do_stats_display’ at ../examples/server_node_efd/efd_server/main.c:136:3: > ../lib/net/rte_ether.h:248:36: warning: ‘snprintf’ output truncated before the last format character [-Wformat-truncation=] > 248 | #define RTE_ETHER_ADDR_PRT_FMT "%02X:%02X:%02X:%02X:%02X:%02X" > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > ../examples/server_node_efd/efd_server/main.c:86:33: note: in expansion of macro ‘RTE_ETHER_ADDR_PRT_FMT’ > 86 | RTE_ETHER_ADDR_PRT_FMT "\n", > | ^~~~~~~~~~~~~~~~~~~~~~ > ../examples/server_node_efd/efd_server/main.c: In function ‘do_stats_display’: > ../examples/server_node_efd/efd_server/main.c:86:59: note: format string is defined here > 86 | RTE_ETHER_ADDR_PRT_FMT "\n", > | > > Fixes: 39aad0e88c58 ("examples/flow_distributor: new example to demonstrate EFD") > Cc: stable@dpdk.org > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Bruce Richardson <bruce.richardson@intel.com> > --- > examples/server_node_efd/efd_server/main.c | 2 +- > examples/server_node_efd/shared/common.h | 3 ++- > 2 files changed, 3 insertions(+), 2 deletions(-) > > diff --git a/examples/server_node_efd/efd_server/main.c b/examples/server_node_efd/efd_server/main.c > index 75ff0ea532..62c3f4a16d 100644 > --- a/examples/server_node_efd/efd_server/main.c > +++ b/examples/server_node_efd/efd_server/main.c > @@ -68,7 +68,7 @@ static const char * > get_printable_mac_addr(uint16_t port) > { > static const char err_address[] = "00:00:00:00:00:00"; > - static char addresses[RTE_MAX_ETHPORTS][sizeof(err_address)]; > + static char addresses[RTE_MAX_ETHPORTS][RTE_ETHER_ADDR_FMT_SIZE + 1]; > struct rte_ether_addr mac; > int ret; > > diff --git a/examples/server_node_efd/shared/common.h b/examples/server_node_efd/shared/common.h > index e1ab7e62b7..6726e2031e 100644 > --- a/examples/server_node_efd/shared/common.h > +++ b/examples/server_node_efd/shared/common.h > @@ -58,8 +58,9 @@ get_rx_queue_name(unsigned int id) > /* > * Buffer for return value. Size calculated by %u being replaced > * by maximum 3 digits (plus an extra byte for safety) > + * Used as ring name, so upper limit is ring name size. > */ > - static char buffer[sizeof(MP_NODE_RXQ_NAME) + 2]; > + static char buffer[RTE_RING_NAMESIZE]; > > snprintf(buffer, sizeof(buffer), MP_NODE_RXQ_NAME, id); > return buffer; > -- > 2.51.0 > ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH v3 2/4] examples/vdpa: fix format overflow warning 2025-11-15 19:36 ` [PATCH v3 0/4] examples: fix " Stephen Hemminger 2025-11-15 19:36 ` [PATCH v3 1/4] examples/server_node_efd: fix format overflow Stephen Hemminger @ 2025-11-15 19:36 ` Stephen Hemminger 2025-11-19 4:31 ` Thomas Monjalon 2025-11-15 19:36 ` [PATCH v3 3/4] examples/ip_reassembly: add check before formatting name Stephen Hemminger 2025-11-15 19:36 ` [PATCH v3 4/4] examples: enable format truncation warning Stephen Hemminger 3 siblings, 1 reply; 40+ messages in thread From: Stephen Hemminger @ 2025-11-15 19:36 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, maxime.coquelin, stable, Bruce Richardson The ifname is limited to 128 characters, but it would allow up to 128 characters as prefix then could overflow creating ifname. Change to limit path prefix (iface) to 123 (128 - sizeof("1024")) to avoid possible format overflow ../examples/vdpa/main.c:501:76: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=] 501 | snprintf(vports[devcnt].ifname, MAX_PATH_LEN, "%s%d", | ^ ../examples/vdpa/main.c:501:25: note: ‘snprintf’ output between 2 and 139 bytes into a destination of size 128 501 | snprintf(vports[devcnt].ifname, MAX_PATH_LEN, "%s%d", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 502 | iface, devcnt); | Fixes: 38f8ab0bbc8d ("vhost: make vDPA framework bus agnostic") Cc: maxime.coquelin@redhat.com Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Bruce Richardson <bruce.richardson@intel.com> --- examples/vdpa/main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index 289db26498..7fd0e55b20 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -22,6 +22,8 @@ #define MAX_PATH_LEN 128 #define MAX_VDPA_SAMPLE_PORTS 1024 +#define stringify(x) (#x) +#define MAX_VDPA_STR_LEN sizeof(stringify(MAX_VDPA_SAMPLE_PORTS)) #define RTE_LOGTYPE_VDPA RTE_LOGTYPE_USER1 struct vdpa_port { @@ -36,7 +38,7 @@ struct vdpa_port { static struct vdpa_port vports[MAX_VDPA_SAMPLE_PORTS]; -static char iface[MAX_PATH_LEN]; +static char iface[MAX_PATH_LEN - MAX_VDPA_STR_LEN]; static int devcnt; static int interactive; static int client_mode; @@ -74,9 +76,8 @@ parse_args(int argc, char **argv) break; /* long options */ case 0: - if (strncmp(long_option[idx].name, "iface", - MAX_PATH_LEN) == 0) { - rte_strscpy(iface, optarg, MAX_PATH_LEN); + if (!strcmp(long_option[idx].name, "iface")) { + rte_strscpy(iface, optarg, sizeof(iface)); printf("iface %s\n", iface); } if (!strcmp(long_option[idx].name, "interactive")) { -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* Re: [PATCH v3 2/4] examples/vdpa: fix format overflow warning 2025-11-15 19:36 ` [PATCH v3 2/4] examples/vdpa: fix format overflow warning Stephen Hemminger @ 2025-11-19 4:31 ` Thomas Monjalon 2025-11-19 9:13 ` Bruce Richardson 0 siblings, 1 reply; 40+ messages in thread From: Thomas Monjalon @ 2025-11-19 4:31 UTC (permalink / raw) To: Stephen Hemminger; +Cc: dev, stable, maxime.coquelin, Bruce Richardson 15/11/2025 20:36, Stephen Hemminger: > +#define stringify(x) (#x) > +#define MAX_VDPA_STR_LEN sizeof(stringify(MAX_VDPA_SAMPLE_PORTS)) Can you use RTE_STR? ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH v3 2/4] examples/vdpa: fix format overflow warning 2025-11-19 4:31 ` Thomas Monjalon @ 2025-11-19 9:13 ` Bruce Richardson 0 siblings, 0 replies; 40+ messages in thread From: Bruce Richardson @ 2025-11-19 9:13 UTC (permalink / raw) To: Thomas Monjalon; +Cc: Stephen Hemminger, dev, stable, maxime.coquelin On Wed, Nov 19, 2025 at 05:31:56AM +0100, Thomas Monjalon wrote: > 15/11/2025 20:36, Stephen Hemminger: > > +#define stringify(x) (#x) > > +#define MAX_VDPA_STR_LEN sizeof(stringify(MAX_VDPA_SAMPLE_PORTS)) > > Can you use RTE_STR? > +1 I had same comment on v2. ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH v3 3/4] examples/ip_reassembly: add check before formatting name 2025-11-15 19:36 ` [PATCH v3 0/4] examples: fix " Stephen Hemminger 2025-11-15 19:36 ` [PATCH v3 1/4] examples/server_node_efd: fix format overflow Stephen Hemminger 2025-11-15 19:36 ` [PATCH v3 2/4] examples/vdpa: fix format overflow warning Stephen Hemminger @ 2025-11-15 19:36 ` Stephen Hemminger 2025-11-15 19:36 ` [PATCH v3 4/4] examples: enable format truncation warning Stephen Hemminger 3 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-15 19:36 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, Konstantin Ananyev, Bruce Richardson In theory, lcore and queue could be so large that mbuf pool name could overflow. But that can never happen since lcore and queue will be in range. Add a check so that static tools know that. Format overflow warnings seen on older versions of Gcc only. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com> Acked-by: Bruce Richardson <bruce.richardson@intel.com> --- examples/ip_reassembly/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/ip_reassembly/main.c b/examples/ip_reassembly/main.c index 17ae76d4ba..25b904dbd4 100644 --- a/examples/ip_reassembly/main.c +++ b/examples/ip_reassembly/main.c @@ -884,6 +884,13 @@ setup_queue_tbl(struct rx_queue *rxq, uint32_t lcore, uint32_t queue) nb_mbuf = RTE_MAX(nb_mbuf, (uint32_t)NB_MBUF); + /* Should never happen but check so that pool name won't be too long. */ + if (lcore > RTE_MAX_LCORE || queue > RTE_MAX_QUEUES_PER_PORT) { + RTE_LOG(ERR, IP_RSMBL, "invalid lcore %u or queue %u", + lcore, queue); + return -1; + } + snprintf(buf, sizeof(buf), "mbuf_pool_%u_%u", lcore, queue); rxq->pool = rte_pktmbuf_pool_create(buf, nb_mbuf, MEMPOOL_CACHE_SIZE, 0, -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v3 4/4] examples: enable format truncation warning 2025-11-15 19:36 ` [PATCH v3 0/4] examples: fix " Stephen Hemminger ` (2 preceding siblings ...) 2025-11-15 19:36 ` [PATCH v3 3/4] examples/ip_reassembly: add check before formatting name Stephen Hemminger @ 2025-11-15 19:36 ` Stephen Hemminger 3 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-15 19:36 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, Bruce Richardson There were several hidden bugs in examples because format truncation warning was disabled. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Bruce Richardson <bruce.richardson@intel.com> --- examples/meson.build | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/meson.build b/examples/meson.build index 8e8968a1fa..25d9c88457 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -78,10 +78,9 @@ else examples = get_option('examples').split(',') allow_skips = false # error out if we can't build a requested app endif + default_cflags = machine_args -if cc.has_argument('-Wno-format-truncation') - default_cflags += '-Wno-format-truncation' -endif + default_ldflags = dpdk_extra_ldflags if get_option('default_library') == 'static' and not is_windows default_ldflags += ['-Wl,--export-dynamic'] -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v4 0/4] examples: fix format-truncation errors 2025-11-10 18:19 [PATCH 0/3] examples: format truncation bugs Stephen Hemminger ` (4 preceding siblings ...) 2025-11-15 19:36 ` [PATCH v3 0/4] examples: fix " Stephen Hemminger @ 2025-11-20 16:21 ` Stephen Hemminger 2025-11-20 16:21 ` [PATCH v4 1/4] examples/server_node_efd: fix format overflow Stephen Hemminger ` (3 more replies) 2025-11-21 17:08 ` [PATCH v5 0/8] tests: fix format truncation warnings Stephen Hemminger 6 siblings, 4 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-20 16:21 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger Enabling format-truncation warning in examples show several possible overflows that are easily addressed. v4 - use RTE_STR() Stephen Hemminger (4): examples/server_node_efd: fix format overflow examples/vdpa: fix format overflow warning examples/ip_reassembly: add check before formatting name examples: enable format truncation warning examples/ip_reassembly/main.c | 7 +++++++ examples/meson.build | 5 ++--- examples/server_node_efd/efd_server/main.c | 2 +- examples/server_node_efd/shared/common.h | 3 ++- examples/vdpa/main.c | 8 ++++---- 5 files changed, 16 insertions(+), 9 deletions(-) -- 2.51.0 ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH v4 1/4] examples/server_node_efd: fix format overflow 2025-11-20 16:21 ` [PATCH v4 0/4] examples: fix format-truncation errors Stephen Hemminger @ 2025-11-20 16:21 ` Stephen Hemminger 2025-11-20 16:22 ` [PATCH v4 2/4] examples/vdpa: fix format overflow warning Stephen Hemminger ` (2 subsequent siblings) 3 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-20 16:21 UTC (permalink / raw) To: dev Cc: Stephen Hemminger, stable, Bruce Richardson, Byron Marohn, Yipeng Wang, Saikrishna Edupuganti, Christian Maciocco, Pablo de Lara If format-truncation is enabled, the compiler detects a string overflow since the snprintf() is putting ethernet address and new line in buffer only sized for the address. Since get_rx_queue_name() is used to create a ring name. The buffer should be sized to be a valid ring name. This fixes some format-overflow warnings and also corrects for future errors. In file included from ../examples/server_node_efd/efd_server/main.c:31: In function ‘get_printable_mac_addr’, inlined from ‘do_stats_display’ at ../examples/server_node_efd/efd_server/main.c:136:3: ../lib/net/rte_ether.h:248:36: warning: ‘snprintf’ output truncated before the last format character [-Wformat-truncation=] 248 | #define RTE_ETHER_ADDR_PRT_FMT "%02X:%02X:%02X:%02X:%02X:%02X" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../examples/server_node_efd/efd_server/main.c:86:33: note: in expansion of macro ‘RTE_ETHER_ADDR_PRT_FMT’ 86 | RTE_ETHER_ADDR_PRT_FMT "\n", | ^~~~~~~~~~~~~~~~~~~~~~ ../examples/server_node_efd/efd_server/main.c: In function ‘do_stats_display’: ../examples/server_node_efd/efd_server/main.c:86:59: note: format string is defined here 86 | RTE_ETHER_ADDR_PRT_FMT "\n", | Fixes: 39aad0e88c58 ("examples/flow_distributor: new example to demonstrate EFD") Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Bruce Richardson <bruce.richardson@intel.com> --- examples/server_node_efd/efd_server/main.c | 2 +- examples/server_node_efd/shared/common.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/server_node_efd/efd_server/main.c b/examples/server_node_efd/efd_server/main.c index 75ff0ea532..62c3f4a16d 100644 --- a/examples/server_node_efd/efd_server/main.c +++ b/examples/server_node_efd/efd_server/main.c @@ -68,7 +68,7 @@ static const char * get_printable_mac_addr(uint16_t port) { static const char err_address[] = "00:00:00:00:00:00"; - static char addresses[RTE_MAX_ETHPORTS][sizeof(err_address)]; + static char addresses[RTE_MAX_ETHPORTS][RTE_ETHER_ADDR_FMT_SIZE + 1]; struct rte_ether_addr mac; int ret; diff --git a/examples/server_node_efd/shared/common.h b/examples/server_node_efd/shared/common.h index e1ab7e62b7..6726e2031e 100644 --- a/examples/server_node_efd/shared/common.h +++ b/examples/server_node_efd/shared/common.h @@ -58,8 +58,9 @@ get_rx_queue_name(unsigned int id) /* * Buffer for return value. Size calculated by %u being replaced * by maximum 3 digits (plus an extra byte for safety) + * Used as ring name, so upper limit is ring name size. */ - static char buffer[sizeof(MP_NODE_RXQ_NAME) + 2]; + static char buffer[RTE_RING_NAMESIZE]; snprintf(buffer, sizeof(buffer), MP_NODE_RXQ_NAME, id); return buffer; -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v4 2/4] examples/vdpa: fix format overflow warning 2025-11-20 16:21 ` [PATCH v4 0/4] examples: fix format-truncation errors Stephen Hemminger 2025-11-20 16:21 ` [PATCH v4 1/4] examples/server_node_efd: fix format overflow Stephen Hemminger @ 2025-11-20 16:22 ` Stephen Hemminger 2025-11-20 16:22 ` [PATCH v4 3/4] examples/ip_reassembly: add check before formatting name Stephen Hemminger 2025-11-20 16:22 ` [PATCH v4 4/4] examples: enable format truncation warning Stephen Hemminger 3 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-20 16:22 UTC (permalink / raw) To: dev Cc: Stephen Hemminger, maxime.coquelin, stable, Bruce Richardson, Chenbo Xia, Adrian Moreno The ifname is limited to 128 characters, but it would allow up to 128 characters as prefix then could overflow creating ifname. Change to limit path prefix (iface) to 123 (128 - sizeof("1024")) to avoid possible format overflow ../examples/vdpa/main.c:501:76: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=] 501 | snprintf(vports[devcnt].ifname, MAX_PATH_LEN, "%s%d", | ^ ../examples/vdpa/main.c:501:25: note: ‘snprintf’ output between 2 and 139 bytes into a destination of size 128 501 | snprintf(vports[devcnt].ifname, MAX_PATH_LEN, "%s%d", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 502 | iface, devcnt); | Fixes: 38f8ab0bbc8d ("vhost: make vDPA framework bus agnostic") Cc: maxime.coquelin@redhat.com Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Bruce Richardson <bruce.richardson@intel.com> --- examples/vdpa/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index 289db26498..08aa933272 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -22,6 +22,7 @@ #define MAX_PATH_LEN 128 #define MAX_VDPA_SAMPLE_PORTS 1024 +#define MAX_VDPA_STR_LEN sizeof(RTE_STR(MAX_VDPA_SAMPLE_PORTS)) #define RTE_LOGTYPE_VDPA RTE_LOGTYPE_USER1 struct vdpa_port { @@ -36,7 +37,7 @@ struct vdpa_port { static struct vdpa_port vports[MAX_VDPA_SAMPLE_PORTS]; -static char iface[MAX_PATH_LEN]; +static char iface[MAX_PATH_LEN - MAX_VDPA_STR_LEN]; static int devcnt; static int interactive; static int client_mode; @@ -74,9 +75,8 @@ parse_args(int argc, char **argv) break; /* long options */ case 0: - if (strncmp(long_option[idx].name, "iface", - MAX_PATH_LEN) == 0) { - rte_strscpy(iface, optarg, MAX_PATH_LEN); + if (!strcmp(long_option[idx].name, "iface")) { + rte_strscpy(iface, optarg, sizeof(iface)); printf("iface %s\n", iface); } if (!strcmp(long_option[idx].name, "interactive")) { -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v4 3/4] examples/ip_reassembly: add check before formatting name 2025-11-20 16:21 ` [PATCH v4 0/4] examples: fix format-truncation errors Stephen Hemminger 2025-11-20 16:21 ` [PATCH v4 1/4] examples/server_node_efd: fix format overflow Stephen Hemminger 2025-11-20 16:22 ` [PATCH v4 2/4] examples/vdpa: fix format overflow warning Stephen Hemminger @ 2025-11-20 16:22 ` Stephen Hemminger 2025-11-20 16:22 ` [PATCH v4 4/4] examples: enable format truncation warning Stephen Hemminger 3 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-20 16:22 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, Konstantin Ananyev, Bruce Richardson In theory, lcore and queue could be so large that mbuf pool name could overflow. But that can never happen since lcore and queue will be in range. Add a check so that static tools know that. Format overflow warnings seen on older versions of Gcc only. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com> Acked-by: Bruce Richardson <bruce.richardson@intel.com> --- examples/ip_reassembly/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/ip_reassembly/main.c b/examples/ip_reassembly/main.c index 17ae76d4ba..25b904dbd4 100644 --- a/examples/ip_reassembly/main.c +++ b/examples/ip_reassembly/main.c @@ -884,6 +884,13 @@ setup_queue_tbl(struct rx_queue *rxq, uint32_t lcore, uint32_t queue) nb_mbuf = RTE_MAX(nb_mbuf, (uint32_t)NB_MBUF); + /* Should never happen but check so that pool name won't be too long. */ + if (lcore > RTE_MAX_LCORE || queue > RTE_MAX_QUEUES_PER_PORT) { + RTE_LOG(ERR, IP_RSMBL, "invalid lcore %u or queue %u", + lcore, queue); + return -1; + } + snprintf(buf, sizeof(buf), "mbuf_pool_%u_%u", lcore, queue); rxq->pool = rte_pktmbuf_pool_create(buf, nb_mbuf, MEMPOOL_CACHE_SIZE, 0, -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v4 4/4] examples: enable format truncation warning 2025-11-20 16:21 ` [PATCH v4 0/4] examples: fix format-truncation errors Stephen Hemminger ` (2 preceding siblings ...) 2025-11-20 16:22 ` [PATCH v4 3/4] examples/ip_reassembly: add check before formatting name Stephen Hemminger @ 2025-11-20 16:22 ` Stephen Hemminger 3 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-20 16:22 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, Bruce Richardson There were several hidden bugs in examples because format truncation warning was disabled. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Bruce Richardson <bruce.richardson@intel.com> --- examples/meson.build | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/meson.build b/examples/meson.build index 8e8968a1fa..25d9c88457 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -78,10 +78,9 @@ else examples = get_option('examples').split(',') allow_skips = false # error out if we can't build a requested app endif + default_cflags = machine_args -if cc.has_argument('-Wno-format-truncation') - default_cflags += '-Wno-format-truncation' -endif + default_ldflags = dpdk_extra_ldflags if get_option('default_library') == 'static' and not is_windows default_ldflags += ['-Wl,--export-dynamic'] -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v5 0/8] tests: fix format truncation warnings 2025-11-10 18:19 [PATCH 0/3] examples: format truncation bugs Stephen Hemminger ` (5 preceding siblings ...) 2025-11-20 16:21 ` [PATCH v4 0/4] examples: fix format-truncation errors Stephen Hemminger @ 2025-11-21 17:08 ` Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 1/8] test: increase size of memzone name Stephen Hemminger ` (7 more replies) 6 siblings, 8 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-21 17:08 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger Enable format truncation warnings on the tests and fix where there was an issue. v5 - one more case of huge page possible name overflow Stephen Hemminger (8): test: increase size of memzone name test: refactor file prefix arg handling test: avoid overflowing huge directory path test: use unit test runner for eal flags test: fix format overflow warning in ACL test test: fix impossible format-truncation in cfgfiles test: fix format overflow in cryptodev test test: re-enable format-truncation warnings app/test/meson.build | 1 - app/test/test_cfgfile.c | 8 +- app/test/test_cryptodev.c | 22 ++++- app/test/test_eal_flags.c | 174 ++++++++++++++++---------------------- app/test/test_memzone.c | 2 +- app/test/test_table_acl.c | 4 +- 6 files changed, 96 insertions(+), 115 deletions(-) -- 2.51.0 ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH v5 1/8] test: increase size of memzone name 2025-11-21 17:08 ` [PATCH v5 0/8] tests: fix format truncation warnings Stephen Hemminger @ 2025-11-21 17:08 ` Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 2/8] test: refactor file prefix arg handling Stephen Hemminger ` (6 subsequent siblings) 7 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-21 17:08 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, Bruce Richardson, Anatoly Burakov The tests were using a name buffer of 20 characters which could overflow if number of memory zones got large. The upper limit is defined as RTE_MEMZONE_NAMESIZE so use that. In function ‘test_memzone_free’, inlined from ‘test_memzone’ at ../app/test/test_memzone.c:1117:6: ../app/test/test_memzone.c:52:35: warning: ‘%u’ directive output may be truncated writing between 1 and 10 bytes into a region of size 4 [-Wformat-truncation=] 52 | #define TEST_MEMZONE_NAME(suffix) "MZ_TEST_" suffix | ^~~~~~~~~~ ../app/test/test_memzone.c:931:46: note: in expansion of macro ‘TEST_MEMZONE_NAME’ 931 | snprintf(name, sizeof(name), TEST_MEMZONE_NAME("tempzone%u"), | ^~~~~~~~~~~~~~~~~ ../app/test/test_memzone.c:52:35: note: directive argument in the range [0, 2147483647] 52 | #define TEST_MEMZONE_NAME(suffix) "MZ_TEST_" suffix | ^~~~~~~~~~ ../app/test/test_memzone.c:931:46: note: in expansion of macro ‘TEST_MEMZONE_NAME’ 931 | snprintf(name, sizeof(name), TEST_MEMZONE_NAME("tempzone%u"), | ^~~~~~~~~~~~~~~~~ ../app/test/test_memzone.c:931:17: note: ‘snprintf’ output between 18 and 27 bytes into a destination of size 20 931 | snprintf(name, sizeof(name), TEST_MEMZONE_NAME("tempzone%u"), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 932 | i); | Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Bruce Richardson <bruce.richardson@intel.com> --- app/test/test_memzone.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test/test_memzone.c b/app/test/test_memzone.c index 506725ea41..6586dad18d 100644 --- a/app/test/test_memzone.c +++ b/app/test/test_memzone.c @@ -872,7 +872,7 @@ test_memzone_free(void) { const struct rte_memzone **mz; int i; - char name[20]; + char name[RTE_MEMZONE_NAMESIZE]; int rc = -1; mz = rte_calloc("memzone_test", rte_memzone_max_get() + 1, -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v5 2/8] test: refactor file prefix arg handling 2025-11-21 17:08 ` [PATCH v5 0/8] tests: fix format truncation warnings Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 1/8] test: increase size of memzone name Stephen Hemminger @ 2025-11-21 17:08 ` Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 3/8] test: avoid overflowing huge directory path Stephen Hemminger ` (5 subsequent siblings) 7 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-21 17:08 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger Make setting up --file-prefix arg logic into a function, and avoid impossible case of file prefix path causing overflow of string. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- app/test/test_eal_flags.c | 126 +++++++++++++------------------------- 1 file changed, 42 insertions(+), 84 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index e32f83d3c8..c2e6c00edb 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -121,6 +121,8 @@ test_misc_flags(void) #define no_shconf "--no-shconf" #define allow "--allow" #define vdev "--vdev" +#define file_prefix "--file-prefix" + #define memtest "memtest" #define memtest1 "memtest1" #define memtest2 "memtest2" @@ -312,6 +314,25 @@ get_number_of_sockets(void) } #endif +static const char * +get_file_prefix(void) +{ +#ifdef RTE_EXEC_ENV_FREEBSD + /* BSD target doesn't support prefixes at this point */ + return ""; +#else + static char prefix[PATH_MAX + sizeof(file_prefix)]; + char tmp[PATH_MAX]; + + if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { + printf("Error - unable to get current prefix!\n"); + return NULL; + } + snprintf(prefix, sizeof(prefix), file_prefix "=%s", tmp); + return prefix; +#endif +} + /* * Test that the app doesn't run with invalid allow option. * Final tests ensures it does run with valid options as sanity check (one @@ -320,18 +341,10 @@ get_number_of_sockets(void) static int test_allow_flag(void) { - unsigned i; -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char * prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); + unsigned int i; + const char *prefix = get_file_prefix(); + if (prefix == NULL) return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif const char *wlinval[][7] = { {prgname, prefix, mp_flag, @@ -387,17 +400,9 @@ test_allow_flag(void) static int test_invalid_b_flag(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char * prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); + const char *prefix = get_file_prefix(); + if (prefix == NULL) return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif const char *blinval[][5] = { {prgname, prefix, mp_flag, "-b", "error"}, @@ -491,17 +496,9 @@ test_invalid_vdev_flag(void) static int test_invalid_r_flag(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char * prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); + const char *prefix = get_file_prefix(); + if (prefix == NULL) return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif const char *rinval[][5] = { {prgname, prefix, mp_flag, "-r", "error"}, @@ -535,17 +532,9 @@ test_invalid_r_flag(void) static int test_missing_c_flag(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char * prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); + const char *prefix = get_file_prefix(); + if (prefix == NULL) return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif /* -c flag but no coremask value */ const char *argv1[] = { prgname, prefix, mp_flag, "-c"}; @@ -694,17 +683,9 @@ test_missing_c_flag(void) static int test_main_lcore_flag(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char *prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); + const char *prefix = get_file_prefix(); + if (prefix == NULL) return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif if (!rte_lcore_is_enabled(0) || !rte_lcore_is_enabled(1)) return TEST_SKIPPED; @@ -751,17 +732,9 @@ test_main_lcore_flag(void) static int test_invalid_n_flag(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char * prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); + const char *prefix = get_file_prefix(); + if (prefix == NULL) return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif /* -n flag but no value */ const char *argv1[] = { prgname, prefix, no_huge, no_shconf, @@ -803,18 +776,12 @@ test_invalid_n_flag(void) static int test_no_hpet_flag(void) { - char prefix[PATH_MAX] = ""; - #ifdef RTE_EXEC_ENV_FREEBSD return 0; #else - char tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); + const char *prefix = get_file_prefix(); + if (prefix == NULL) return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif /* With --no-hpet */ const char *argv1[] = {prgname, prefix, mp_flag, no_hpet}; @@ -829,6 +796,7 @@ test_no_hpet_flag(void) printf("Error - process did not run ok without --no-hpet flag\n"); return -1; } +# return 0; } @@ -898,6 +866,7 @@ test_no_huge_flag(void) printf("Error - process run ok with --no-huge and --huge-worker-stack=size flags"); return -1; } +#endif return 0; } @@ -913,17 +882,14 @@ test_misc_flags(void) const char * prefix = ""; const char * nosh_prefix = ""; #else - char prefix[PATH_MAX], tmp[PATH_MAX]; + const char *prefix = get_file_prefix(); const char * nosh_prefix = "--file-prefix=noshconf"; FILE * hugedir_handle = NULL; char line[PATH_MAX] = {0}; unsigned i, isempty = 1; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); + if (prefix == NULL) return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); /* * get first valid hugepage path @@ -1525,17 +1491,9 @@ populate_socket_mem_param(int num_sockets, const char *mem, static int test_memory_flags(void) { -#ifdef RTE_EXEC_ENV_FREEBSD - /* BSD target doesn't support prefixes at this point */ - const char * prefix = ""; -#else - char prefix[PATH_MAX], tmp[PATH_MAX]; - if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { - printf("Error - unable to get current prefix!\n"); + const char *prefix = get_file_prefix(); + if (prefix == NULL) return -1; - } - snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); -#endif /* valid -m flag and mp flag */ const char *argv0[] = {prgname, prefix, mp_flag, -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v5 3/8] test: avoid overflowing huge directory path 2025-11-21 17:08 ` [PATCH v5 0/8] tests: fix format truncation warnings Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 1/8] test: increase size of memzone name Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 2/8] test: refactor file prefix arg handling Stephen Hemminger @ 2025-11-21 17:08 ` Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 4/8] test: use unit test runner for eal flags Stephen Hemminger ` (4 subsequent siblings) 7 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-21 17:08 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, Anatoly Burakov Since the tests construct a mulit-part path in huge pages directory, avoid overflowing the string buffer by limiting the possible huge page directory. Can never happen in real life, but compiler gives warnings about string overflow that it could. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> --- app/test/test_eal_flags.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index c2e6c00edb..1d1ca87e0f 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -172,7 +172,7 @@ process_hugefiles(const char * prefix, enum hugepage_action action) struct dirent *dirent = NULL; char hugefile_prefix[PATH_MAX] = {0}; - char hugedir[PATH_MAX] = {0}; + char hugedir[PATH_MAX - NAME_MAX] = {0}; char line[PATH_MAX] = {0}; int fd, lck_result, result = 0; @@ -222,7 +222,7 @@ process_hugefiles(const char * prefix, enum hugepage_action action) break; case HUGEPAGE_DELETE: { - char file_path[PATH_MAX] = {0}; + char file_path[PATH_MAX + NAME_MAX] = {0}; snprintf(file_path, sizeof(file_path), "%s/%s", hugedir, dirent->d_name); @@ -873,7 +873,7 @@ test_no_huge_flag(void) static int test_misc_flags(void) { - char hugepath[PATH_MAX] = {0}; + char hugepath[PATH_MAX - NAME_MAX] = {0}; char hugepath_dir[PATH_MAX] = {0}; char hugepath_dir2[PATH_MAX] = {0}; char hugepath_dir3[PATH_MAX] = {0}; -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v5 4/8] test: use unit test runner for eal flags 2025-11-21 17:08 ` [PATCH v5 0/8] tests: fix format truncation warnings Stephen Hemminger ` (2 preceding siblings ...) 2025-11-21 17:08 ` [PATCH v5 3/8] test: avoid overflowing huge directory path Stephen Hemminger @ 2025-11-21 17:08 ` Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 5/8] test: fix format overflow warning in ACL test Stephen Hemminger ` (3 subsequent siblings) 7 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-21 17:08 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, Anatoly Burakov Make the sub tests in eal flags suite into a group so that they are not individual tests. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> --- app/test/test_eal_flags.c | 46 +++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 1d1ca87e0f..398f038bc8 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -777,7 +777,7 @@ static int test_no_hpet_flag(void) { #ifdef RTE_EXEC_ENV_FREEBSD - return 0; + return TEST_SKIPPED; #else const char *prefix = get_file_prefix(); if (prefix == NULL) @@ -796,8 +796,8 @@ test_no_hpet_flag(void) printf("Error - process did not run ok without --no-hpet flag\n"); return -1; } -# return 0; +#endif } /* @@ -866,7 +866,7 @@ test_no_huge_flag(void) printf("Error - process run ok with --no-huge and --huge-worker-stack=size flags"); return -1; } -#endif + return 0; } @@ -1208,7 +1208,7 @@ test_file_prefix(void) char prefix[PATH_MAX] = ""; #ifdef RTE_EXEC_ENV_FREEBSD - return 0; + return TEST_SKIPPED; #else if (get_current_prefix(prefix, sizeof(prefix)) == NULL) { printf("Error - unable to get current prefix!\n"); @@ -1650,15 +1650,29 @@ test_memory_flags(void) #endif /* !RTE_EXEC_ENV_WINDOWS */ -REGISTER_FAST_TEST(eal_flags_c_opt_autotest, false, false, test_missing_c_flag); -REGISTER_FAST_TEST(eal_flags_main_opt_autotest, false, false, test_main_lcore_flag); -REGISTER_FAST_TEST(eal_flags_n_opt_autotest, false, false, test_invalid_n_flag); -REGISTER_FAST_TEST(eal_flags_hpet_autotest, false, false, test_no_hpet_flag); -REGISTER_FAST_TEST(eal_flags_no_huge_autotest, false, false, test_no_huge_flag); -REGISTER_FAST_TEST(eal_flags_a_opt_autotest, false, false, test_allow_flag); -REGISTER_FAST_TEST(eal_flags_b_opt_autotest, false, false, test_invalid_b_flag); -REGISTER_FAST_TEST(eal_flags_vdev_opt_autotest, false, false, test_invalid_vdev_flag); -REGISTER_FAST_TEST(eal_flags_r_opt_autotest, false, false, test_invalid_r_flag); -REGISTER_FAST_TEST(eal_flags_mem_autotest, false, false, test_memory_flags); -REGISTER_FAST_TEST(eal_flags_file_prefix_autotest, false, false, test_file_prefix); -REGISTER_FAST_TEST(eal_flags_misc_autotest, false, false, test_misc_flags); +static struct unit_test_suite eal_flags_test_suite = { + .suite_name = "EAL flags unit test suite", + .unit_test_cases = { + TEST_CASE(test_missing_c_flag), + TEST_CASE(test_main_lcore_flag), + TEST_CASE(test_invalid_n_flag), + TEST_CASE(test_no_hpet_flag), + TEST_CASE(test_no_huge_flag), + TEST_CASE(test_allow_flag), + TEST_CASE(test_invalid_b_flag), + TEST_CASE(test_invalid_vdev_flag), + TEST_CASE(test_invalid_r_flag), + TEST_CASE(test_memory_flags), + TEST_CASE(test_file_prefix), + TEST_CASE(test_misc_flags), + TEST_CASES_END() + } +}; + +static int +test_eal_flags(void) +{ + return unit_test_suite_runner(&eal_flags_test_suite); +} + +REGISTER_FAST_TEST(eal_flags_autotest, false, false, test_eal_flags); -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v5 5/8] test: fix format overflow warning in ACL test 2025-11-21 17:08 ` [PATCH v5 0/8] tests: fix format truncation warnings Stephen Hemminger ` (3 preceding siblings ...) 2025-11-21 17:08 ` [PATCH v5 4/8] test: use unit test runner for eal flags Stephen Hemminger @ 2025-11-21 17:08 ` Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 6/8] test: fix impossible format-truncation in cfgfiles Stephen Hemminger ` (2 subsequent siblings) 7 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-21 17:08 UTC (permalink / raw) To: dev Cc: Stephen Hemminger, stable, Anatoly Burakov, Cristian Dumitrescu, Pablo de Lara This test has an array of input lines, but the two dimensional array confuses compiler length checks. Convert to an array of pointers to fixed strings which avoids the problem. Make both variables static since not shared with other code. Fixes: 5205954791cb ("app/test: packet framework unit tests") Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> --- app/test/test_table_acl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/test/test_table_acl.c b/app/test/test_table_acl.c index dff9bddfb9..94edf37234 100644 --- a/app/test/test_table_acl.c +++ b/app/test/test_table_acl.c @@ -317,7 +317,7 @@ parse_cb_ipv4_rule_del(char *str, struct rte_table_acl_rule_delete_params *v) * separated by ' : ', just ':'. It's a lot more readable and * cleaner, IMO. */ -char lines[][128] = { +static const char * const lines[] = { "@0.0.0.0/0 0.0.0.0/0 0:65535 0:65535 2/0xff", /* Protocol check */ "@192.168.3.1/32 0.0.0.0/0 0:65535 0:65535 0/0", /* Src IP checl */ "@0.0.0.0/0 10.4.4.1/32 0:65535 0:65535 0/0", /* dst IP check */ @@ -325,7 +325,7 @@ char lines[][128] = { "@0.0.0.0/0 0.0.0.0/0 0:65535 206:206 0/0", /* dst port check */ }; -char line[128]; +static char line[128]; static int -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v5 6/8] test: fix impossible format-truncation in cfgfiles 2025-11-21 17:08 ` [PATCH v5 0/8] tests: fix format truncation warnings Stephen Hemminger ` (4 preceding siblings ...) 2025-11-21 17:08 ` [PATCH v5 5/8] test: fix format overflow warning in ACL test Stephen Hemminger @ 2025-11-21 17:08 ` Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 7/8] test: fix format overflow in cryptodev test Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 8/8] test: re-enable format-truncation warnings Stephen Hemminger 7 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-21 17:08 UTC (permalink / raw) To: dev Cc: Stephen Hemminger, stable, Anatoly Burakov, Cristian Dumitrescu, Bruce Richardson Although, it is not possible on Linux (which always uses /tmp) the compiler complains about possible snprintf() truncation. Use existing code to make empty tmp file which puts the OS specific code in one spot and avoids any races if two tests are run at once. Fixes: be22019a58c4 ("test: restore cfgfile tests") Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> --- app/test/test_cfgfile.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/test/test_cfgfile.c b/app/test/test_cfgfile.c index b189d9d7a5..eabf155404 100644 --- a/app/test/test_cfgfile.c +++ b/app/test/test_cfgfile.c @@ -178,12 +178,8 @@ test_cfgfile_realloc_sections(void) ret = remove(filename); TEST_ASSERT_SUCCESS(ret, "Failed to remove file"); - char tmp[PATH_MAX] = "/tmp/"; -#ifdef RTE_EXEC_ENV_WINDOWS - ret = GetTempPathA(sizeof(tmp), tmp); - TEST_ASSERT(ret > 0, "Failed to get tmp directory"); -#endif - snprintf(filename, sizeof(filename), "%s%s", tmp, "cfg_save.ini"); + ret = make_tmp_file(filename, "save", ""); + TEST_ASSERT(ret == 0, "Failed to make empty tmp filename for save"); ret = rte_cfgfile_save(cfgfile, filename); TEST_ASSERT_SUCCESS(ret, "Failed to save to %s", filename); -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v5 7/8] test: fix format overflow in cryptodev test 2025-11-21 17:08 ` [PATCH v5 0/8] tests: fix format truncation warnings Stephen Hemminger ` (5 preceding siblings ...) 2025-11-21 17:08 ` [PATCH v5 6/8] test: fix impossible format-truncation in cfgfiles Stephen Hemminger @ 2025-11-21 17:08 ` Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 8/8] test: re-enable format-truncation warnings Stephen Hemminger 7 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-21 17:08 UTC (permalink / raw) To: dev Cc: Stephen Hemminger, Anatoly Burakov, Akhil Goyal, Fan Zhang, Declan Doherty, Hemant Agrawal, Ciara Power The vdev args buffer could in theory get truncated if there were lots of sockets or lcores. Handle that by checking return value of snprintf. Fixes: 8bfdd8a7f0f1 ("test/crypto: refactor to use sub test suites") Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> --- app/test/test_cryptodev.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 9bdd357727..bd6a2d3fa6 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -17713,8 +17713,16 @@ scheduler_testsuite_setup(void) RTE_LCORE_FOREACH_WORKER(i) { if (worker_core_count > 1) break; - snprintf(vdev_args, sizeof(vdev_args), - "%s%d", temp_str, i); + ret = snprintf(vdev_args, sizeof(vdev_args), + "%s%d", temp_str, i); + + /* If too many args the result will have been truncated */ + if (ret >= VDEV_ARGS_SIZE) { + RTE_LOG(ERR, USER1, + "Cryptodev scheduler test vdev arg size exceeded\n"); + return TEST_FAILED; + } + strcpy(temp_str, vdev_args); strlcat(temp_str, ";", sizeof(temp_str)); worker_core_count++; @@ -17728,8 +17736,14 @@ scheduler_testsuite_setup(void) return TEST_FAILED; } strcpy(temp_str, vdev_args); - snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", - temp_str, socket_id); + ret = snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", + temp_str, socket_id); + if (ret >= VDEV_ARGS_SIZE) { + RTE_LOG(ERR, USER1, + "Cryptodev scheduler test vdev arg size exceeded\n"); + return TEST_FAILED; + } + RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); nb_devs = rte_cryptodev_device_count_by_driver( rte_cryptodev_driver_id_get( -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH v5 8/8] test: re-enable format-truncation warnings 2025-11-21 17:08 ` [PATCH v5 0/8] tests: fix format truncation warnings Stephen Hemminger ` (6 preceding siblings ...) 2025-11-21 17:08 ` [PATCH v5 7/8] test: fix format overflow in cryptodev test Stephen Hemminger @ 2025-11-21 17:08 ` Stephen Hemminger 7 siblings, 0 replies; 40+ messages in thread From: Stephen Hemminger @ 2025-11-21 17:08 UTC (permalink / raw) To: dev; +Cc: Stephen Hemminger, Bruce Richardson Tests should be built with warnings. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Bruce Richardson <bruce.richardson@intel.com> --- app/test/meson.build | 1 - 1 file changed, 1 deletion(-) diff --git a/app/test/meson.build b/app/test/meson.build index efec42a6bf..b00260c0e9 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -260,7 +260,6 @@ cflags += no_wvla_cflag extra_flags = [ # Strict-aliasing rules are violated by uint8_t[] to context size casts. '-fno-strict-aliasing', - '-Wno-format-truncation', ] foreach arg: extra_flags -- 2.51.0 ^ permalink raw reply related [flat|nested] 40+ messages in thread
end of thread, other threads:[~2025-11-21 17:10 UTC | newest] Thread overview: 40+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-11-10 18:19 [PATCH 0/3] examples: format truncation bugs Stephen Hemminger 2025-11-10 18:19 ` [PATCH 1/3] examples/server_node_efd: fix format overflow Stephen Hemminger 2025-11-10 18:19 ` [PATCH 2/3] examples/vdpa: fix format overflow warning Stephen Hemminger 2025-11-10 18:19 ` [PATCH 3/3] examples: re-enable format truncation warning Stephen Hemminger 2025-11-11 22:17 ` [PATCH v2 0/7] fix format-truncation warnings Stephen Hemminger 2025-11-11 22:17 ` [PATCH v2 1/7] examples/server_node_efd: fix format overflow Stephen Hemminger 2025-11-11 22:17 ` [PATCH v2 2/7] examples/vdpa: fix format overflow warning Stephen Hemminger 2025-11-14 15:59 ` Bruce Richardson 2025-11-11 22:17 ` [PATCH v2 3/7] examples/ip_reassembly: add check before formatting name Stephen Hemminger 2025-11-12 14:50 ` Konstantin Ananyev 2025-11-14 16:05 ` Bruce Richardson 2025-11-11 22:17 ` [PATCH v2 4/7] examples: re-enable format truncation warning Stephen Hemminger 2025-11-14 16:07 ` Bruce Richardson 2025-11-11 22:17 ` [PATCH v2 5/7] test: refactor file prefix arg handling Stephen Hemminger 2025-11-11 22:17 ` [PATCH v2 6/7] test: increase size of memzone name Stephen Hemminger 2025-11-14 16:07 ` Bruce Richardson 2025-11-11 22:17 ` [PATCH v2 7/7] test: re-enable format-truncation warnings Stephen Hemminger 2025-11-14 16:08 ` Bruce Richardson 2025-11-15 19:36 ` [PATCH v3 0/4] examples: fix " Stephen Hemminger 2025-11-15 19:36 ` [PATCH v3 1/4] examples/server_node_efd: fix format overflow Stephen Hemminger 2025-11-17 8:50 ` Bruce Richardson 2025-11-15 19:36 ` [PATCH v3 2/4] examples/vdpa: fix format overflow warning Stephen Hemminger 2025-11-19 4:31 ` Thomas Monjalon 2025-11-19 9:13 ` Bruce Richardson 2025-11-15 19:36 ` [PATCH v3 3/4] examples/ip_reassembly: add check before formatting name Stephen Hemminger 2025-11-15 19:36 ` [PATCH v3 4/4] examples: enable format truncation warning Stephen Hemminger 2025-11-20 16:21 ` [PATCH v4 0/4] examples: fix format-truncation errors Stephen Hemminger 2025-11-20 16:21 ` [PATCH v4 1/4] examples/server_node_efd: fix format overflow Stephen Hemminger 2025-11-20 16:22 ` [PATCH v4 2/4] examples/vdpa: fix format overflow warning Stephen Hemminger 2025-11-20 16:22 ` [PATCH v4 3/4] examples/ip_reassembly: add check before formatting name Stephen Hemminger 2025-11-20 16:22 ` [PATCH v4 4/4] examples: enable format truncation warning Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 0/8] tests: fix format truncation warnings Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 1/8] test: increase size of memzone name Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 2/8] test: refactor file prefix arg handling Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 3/8] test: avoid overflowing huge directory path Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 4/8] test: use unit test runner for eal flags Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 5/8] test: fix format overflow warning in ACL test Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 6/8] test: fix impossible format-truncation in cfgfiles Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 7/8] test: fix format overflow in cryptodev test Stephen Hemminger 2025-11-21 17:08 ` [PATCH v5 8/8] test: re-enable format-truncation warnings Stephen Hemminger
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).