net/mlx5: fix build with GCC 12 and ASan
PATCH 1/1 net/mlx5: fix build with GCC 12 and ASan
Building with gcc 12 and ASan raises this warning:
../drivers/net/mlx5/mlx5_txpp.c: In function ‘mlx5_txpp_xstats_get_names’:../drivers/net/mlx5/mlx5_txpp.c:1066:25: error: ‘strncpy’ specified bound
64 equals destination size [-Werror=stringop-truncation]
1066 | strncpy(xstats_names[i + n_used].name,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1067 | mlx5_txpp_stat_names[i],
| ~~~~~~~~~~~~~~~~~~~~~~~~
1068 | RTE_ETH_XSTATS_NAME_SIZE);
| ~~~~~~~~~~~~~~~~~~~~~~~~~cc1: all warnings being treated as errors
Prefer strlcpy.
--- drivers/net/mlx5/mlx5_txpp.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/mlx5/mlx5_txpp.c +1 -3
@@ -1063,11 +1063,9 @@ int mlx5_txpp_xstats_get_names(struct rte_eth_dev *dev __rte_unused,if (n >= n_used + n_txpp && xstats_names) {for (i =0 ; i < n_txpp; ++i) { -strncpy (xstats_names[i + n_used].name, +strlcpy (xstats_names[i + n_used].name, mlx5_txpp_stat_names[i],RTE_ETH_XSTATS_NAME_SIZE ); - xstats_names[i + n_used].name - [RTE_ETH_XSTATS_NAME_SIZE -1 ] =0 ; } }return n_used + n_txpp;
Signature · 1 line
2.39.2
Quoted 12 lines · David Marchand
Building with gcc 12 and ASan raises this warning:
../drivers/net/mlx5/mlx5_txpp.c: In function ‘mlx5_txpp_xstats_get_names’:../drivers/net/mlx5/mlx5_txpp.c:1066:25: error: ‘strncpy’ specified bound
64 equals destination size [-Werror=stringop-truncation]1066 | strncpy(xstats_names[i + n_used].name, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1067 | mlx5_txpp_stat_names[i], | ~~~~~~~~~~~~~~~~~~~~~~~~ 1068 | RTE_ETH_XSTATS_NAME_SIZE); | ~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 8 lines
cc1: all warnings being treated as errors
Prefer strlcpy.
Fixes 3b025c0ca425 ("net/mlx5: provide send scheduling error statistics")Signed-off-by David Marchand <[email protected]>
Review please?
Signature · 1 line
David Marchand
Hi, David
Thank you for the fix.
I see the quite similar strncpy() usage in mlx5_xstats_get_names() routine. Does compiler complain about?
With best regards,
Slava
Quoted 52 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: четверг, 9 марта 2023 г. 11:03
To: [email protected]
Cc: [email protected]; Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>
Subject: [PATCH] net/mlx5: fix build with GCC 12 and ASanBuilding with gcc 12 and ASan raises this warning:
../drivers/net/mlx5/mlx5_txpp.c: In function ‘mlx5_txpp_xstats_get_names’:../drivers/net/mlx5/mlx5_txpp.c:1066:25: error: ‘strncpy’ specified bound
64 equals destination size [-Werror=stringop-truncation]1066 | strncpy(xstats_names[i + n_used].name, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1067 | mlx5_txpp_stat_names[i], | ~~~~~~~~~~~~~~~~~~~~~~~~ 1068 | RTE_ETH_XSTATS_NAME_SIZE); | ~~~~~~~~~~~~~~~~~~~~~~~~~cc1: all warnings being treated as errors
Prefer strlcpy.
Fixes 3b025c0ca425 ("net/mlx5: provide send scheduling error statistics")Signed-off-by David Marchand <[email protected]>--- drivers/net/mlx5/mlx5_txpp.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/net/mlx5/mlx5_txpp.c +1
-3@@ -1063,11 +1063,9 @@ int mlx5_txpp_xstats_get_names(struct rte_eth_dev *dev __rte_unused,if (n >= n_used + n_txpp && xstats_names) {for (i =0 ; i < n_txpp; ++i) { -strncpy (xstats_names[i + n_used].name, +strlcpy (xstats_names[i + n_used].name, mlx5_txpp_stat_names[i],RTE_ETH_XSTATS_NAME_SIZE ); - xstats_names[i + n_used].name - [RTE_ETH_XSTATS_NAME_SIZE -1 ] =0 ; }drivers/net/mlx5/mlx5_txpp.c +0
-1}return n_used + n_txpp; --2.39.2
Quoted 6 lines · Slava Ovsiienko
Hi, David
Thank you for the fix.
I see the quite similarstrncpy()usage inmlx5_xstats_get_names()routine. Does compiler complain about?
Strangely.. no.
But we could switch to strlcpy too.
What is your preferrence?
Signature · 1 line
David Marchand
Hi,
I would prefer to fix both.
With best regards,
Slava
Quoted 23 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: среда, 15 марта 2023 г. 12:05
To: Slava Ovsiienko <[email protected]>
Cc: [email protected]; [email protected]; Matan Azrad <[email protected]>
Subject: Re: [PATCH] net/mlx5: fix build with GCC 12 and ASanQuoted 6 lines · Slava Ovsiienko
Hi, David
Thank you for the fix.
I see the quite similarstrncpy()usage inmlx5_xstats_get_names()routine. Does compiler complain about?Strangely.. no.
But we could switch to strlcpy too.
What is your preferrence?--
David Marchand
PATCH v2 1/1 net/mlx5: fix build with GCC 12 and ASan
In reply to David MarchandBuilding with gcc 12 and ASan raises this warning:
../drivers/net/mlx5/mlx5_txpp.c: In function ‘mlx5_txpp_xstats_get_names’:../drivers/net/mlx5/mlx5_txpp.c:1066:25: error: ‘strncpy’ specified bound
64 equals destination size [-Werror=stringop-truncation]
1066 | strncpy(xstats_names[i + n_used].name,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1067 | mlx5_txpp_stat_names[i],
| ~~~~~~~~~~~~~~~~~~~~~~~~
1068 | RTE_ETH_XSTATS_NAME_SIZE);
| ~~~~~~~~~~~~~~~~~~~~~~~~~cc1: all warnings being treated as errors
Prefer strlcpy for xstats.
---
Changes since v1:
- updated mlx5_xstats_get_names too,
--- drivers/net/mlx5/mlx5_stats.c | 3 +-- drivers/net/mlx5/mlx5_txpp.c | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_stats.c +1 -2
@@ -288,10 +288,9 @@ mlx5_xstats_get_names(struct rte_eth_dev *dev,if (n >= mlx5_xstats_n && xstats_names) {for (i =0 ; i != mlx5_xstats_n; ++i) { -strncpy (xstats_names[i].name, +strlcpy (xstats_names[i].name, xstats_ctrl->info[i].dpdk_name,RTE_ETH_XSTATS_NAME_SIZE ); - xstats_names[i].name[RTE_ETH_XSTATS_NAME_SIZE -1 ] =0 ; } } mlx5_xstats_n = mlx5_txpp_xstats_get_names(dev, xstats_names,
drivers/net/mlx5/mlx5_txpp.c +1 -3
@@ -1063,11 +1063,9 @@ int mlx5_txpp_xstats_get_names(struct rte_eth_dev *dev __rte_unused,if (n >= n_used + n_txpp && xstats_names) {for (i =0 ; i < n_txpp; ++i) { -strncpy (xstats_names[i + n_used].name, +strlcpy (xstats_names[i + n_used].name, mlx5_txpp_stat_names[i],RTE_ETH_XSTATS_NAME_SIZE ); - xstats_names[i + n_used].name - [RTE_ETH_XSTATS_NAME_SIZE -1 ] =0 ; } }return n_used + n_txpp;
Signature · 1 line
2.39.2
Hi,
Quoted 26 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Wednesday, March 22, 2023 7:06 PM
To: [email protected]
Cc: [email protected]; Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>
Subject: [PATCH v2] net/mlx5: fix build with GCC 12 and ASanBuilding with gcc 12 and ASan raises this warning:
../drivers/net/mlx5/mlx5_txpp.c: In function ‘mlx5_txpp_xstats_get_names’:../drivers/net/mlx5/mlx5_txpp.c:1066:25: error: ‘strncpy’ specified bound
64 equals destination size [-Werror=stringop-truncation]1066 | strncpy(xstats_names[i + n_used].name, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1067 | mlx5_txpp_stat_names[i], | ~~~~~~~~~~~~~~~~~~~~~~~~ 1068 | RTE_ETH_XSTATS_NAME_SIZE); | ~~~~~~~~~~~~~~~~~~~~~~~~~cc1: all warnings being treated as errors
Prefer strlcpy for xstats.
Fixes 3b025c0ca425 ("net/mlx5: provide send scheduling error statistics")
Quoted 6 lines
Signed-off-by David Marchand <[email protected]>---
Changes since v1:
- updatedmlx5_xstats_get_namestoo,---
Patch applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh