Skip to contentSkip to conversation

examples/ethtool: fix buffer size for pkt pool name

PATCH Superseded Shani Peretz 3 participants 5 messages Dec 3, 2025 – Jan 28

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/ethtool: fix buffer size for pkt pool name

Increase str_name buffer size from 16 to 32 bytes to fit the provided format. The previous size was insufficient as the format string "pkt_pool%i" can produce up to 19 bytes (8 for "pkt_pool", up to 10 for integer value, and 1 for null terminator).

Fixes bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application")
---
 examples/ethtool/ethtool-app/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
examples/ethtool/ethtool-app/main.c +2 -2
index 1f011a9321..06605b4202 100644
@@ -92,7 +92,7 @@ static void setup_ports(struct app_config *app_cfg, int cnt_ports)
 	int size_pktpool;
 	struct rte_eth_conf cfg_port;
 	struct rte_eth_dev_info dev_info;
-	char str_name[16];
+	char str_name[32];
 	uint16_t nb_rxd = PORT_RX_QUEUE_SIZE;
 	uint16_t nb_txd = PORT_TX_QUEUE_SIZE;
 	int ret;
@@ -112,7 +112,7 @@ static void setup_ports(struct app_config *app_cfg, int cnt_ports)
 		size_pktpool = dev_info.rx_desc_lim.nb_max +
 			dev_info.tx_desc_lim.nb_max + PKTPOOL_EXTRA_SIZE;
 
-		snprintf(str_name, 16, "pkt_pool%i", idx_port);
+		snprintf(str_name, sizeof(str_name), "pkt_pool%i", idx_port);
 		ptr_port->pkt_pool = rte_pktmbuf_pool_create(
 			str_name,
 			size_pktpool, PKTPOOL_CACHE,
Signature · 1 line
2.34.1
#1 lore raw
Quoted 18 lines · On Wed, 3 Dec 2025 13:01:57 +0200 Shani Peretz <[email protected]> wrote:

Increase str_name buffer size from 16 to 32 bytes to fit the provided format. The previous size was insufficient as the format string "pkt_pool%i" can produce up to 19 bytes (8 for "pkt_pool", up to 10 for integer value, and 1 for null terminator).

Fixes bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application")
---
 examples/ethtool/ethtool-app/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
examples/ethtool/ethtool-app/main.c +0 -0
index 1f011a9321..06605b4202 100644

examples/ethtool/ethtool-app/main.c static void setup_ports(struct app_config *app_cfg, int cnt_ports) · line 95

Quoted 5 lines
examples/ethtool/ethtool-app/main.c +1 -1
@@ -92,7 +92,7 @@ static void setup_ports(struct app_config *app_cfg, int cnt_ports)
 	int size_pktpool;
 	struct rte_eth_conf cfg_port;
 	struct rte_eth_dev_info dev_info;
-	char str_name[16];
+	char str_name[32];

Don't use hard coded constant, instead use RTE_MEMPOOL_NAMESIZE which is not 32, but 32 - 4 + 1 = 29

#2 lore raw

PATCH v2 1/1 examples/ethtool: fix buffer size for pkt pool name

In reply to Shani Peretz

Use RTE_MEMPOOL_NAMESIZE for str_name buffer size instead of the hardcoded value 16, which was insufficient as the format string "pkt_pool%i" can produce up to 19 bytes (8 for "pkt_pool", up to 10 for integer value, and 1 for null terminator).

Fixes bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application")
---
 examples/ethtool/ethtool-app/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
examples/ethtool/ethtool-app/main.c +2 -2
index 1f011a9321..d380f69cea 100644
@@ -92,7 +92,7 @@ static void setup_ports(struct app_config *app_cfg, int cnt_ports)
 	int size_pktpool;
 	struct rte_eth_conf cfg_port;
 	struct rte_eth_dev_info dev_info;
-	char str_name[16];
+	char str_name[RTE_MEMPOOL_NAMESIZE];
 	uint16_t nb_rxd = PORT_RX_QUEUE_SIZE;
 	uint16_t nb_txd = PORT_TX_QUEUE_SIZE;
 	int ret;
@@ -112,7 +112,7 @@ static void setup_ports(struct app_config *app_cfg, int cnt_ports)
 		size_pktpool = dev_info.rx_desc_lim.nb_max +
 			dev_info.tx_desc_lim.nb_max + PKTPOOL_EXTRA_SIZE;
 
-		snprintf(str_name, 16, "pkt_pool%i", idx_port);
+		snprintf(str_name, sizeof(str_name), "pkt_pool%i", idx_port);
 		ptr_port->pkt_pool = rte_pktmbuf_pool_create(
 			str_name,
 			size_pktpool, PKTPOOL_CACHE,
Signature · 1 line
2.43.0
Acked-by on v2 1/1
#3 lore raw
Quoted 9 lines · On Mon, 22 Dec 2025 10:38:58 +0200 Shani Peretz <[email protected]> wrote:

Use RTE_MEMPOOL_NAMESIZE for str_name buffer size instead of the hardcoded value 16, which was insufficient as the format string "pkt_pool%i" can produce up to 19 bytes (8 for "pkt_pool", up to 10 for integer value, and 1 for null terminator).

Fixes bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application")
#4 lore raw

23/12/2025 00:31, Stephen Hemminger:

Quoted 8 lines
Quoted 5 lines · On Mon, 22 Dec 2025 10:38:58 +0200 Shani Peretz <[email protected]> wrote:

Use RTE_MEMPOOL_NAMESIZE for str_name buffer size instead of the hardcoded value 16, which was insufficient as the format string "pkt_pool%i" can produce up to 19 bytes (8 for "pkt_pool", up to 10 for integer value, and 1 for null terminator).

Quoted 6 lines
Quoted 4 lines
Fixes bda68ab9d1e7 ("examples/ethtool: add user-space ethtool sample application")

Applied, thanks.