[v5,07/52] pdump: replace strerror with reentrant version

Message ID 20241104111037.3632161-8-huangdengdui@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series replace strerror |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

huangdengdui Nov. 4, 2024, 11:09 a.m. UTC
The function strerror() is insecure in a multi-thread environment.
This patch uses strerror_r() to replace it.

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
---
 lib/pdump/rte_pdump.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
  

Patch

diff --git a/lib/pdump/rte_pdump.c b/lib/pdump/rte_pdump.c
index 679c3dd0b5..83cb8b75d8 100644
--- a/lib/pdump/rte_pdump.c
+++ b/lib/pdump/rte_pdump.c
@@ -284,6 +284,7 @@  static int
 set_pdump_rxtx_cbs(const struct pdump_request *p)
 {
 	uint16_t nb_rx_q = 0, nb_tx_q = 0, end_q, queue;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	uint16_t port;
 	int ret = 0;
 	struct rte_bpf *filter = NULL;
@@ -335,9 +336,11 @@  set_pdump_rxtx_cbs(const struct pdump_request *p)
 
 		ret = rte_eth_dev_info_get(port, &dev_info);
 		if (ret != 0) {
+			if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret);
 			PDUMP_LOG_LINE(ERR,
 				"Error during getting device (port %u) info: %s",
-				port, strerror(-ret));
+				port, errmsg);
 			return ret;
 		}
 
@@ -731,15 +734,18 @@  int
 rte_pdump_stats(uint16_t port, struct rte_pdump_stats *stats)
 {
 	struct rte_eth_dev_info dev_info;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	const struct rte_memzone *mz;
 	int ret;
 
 	memset(stats, 0, sizeof(*stats));
 	ret = rte_eth_dev_info_get(port, &dev_info);
 	if (ret != 0) {
+		if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret);
 		PDUMP_LOG_LINE(ERR,
 			  "Error during getting device (port %u) info: %s",
-			  port, strerror(-ret));
+			  port, errmsg);
 		return ret;
 	}