[v5,36/52] net/ixgbe: replace strerror with reentrant version

Message ID 20241104111037.3632161-37-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:10 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>
---
 drivers/net/ixgbe/ixgbe_testpmd.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
  

Patch

diff --git a/drivers/net/ixgbe/ixgbe_testpmd.c b/drivers/net/ixgbe/ixgbe_testpmd.c
index e0d161eafe..d019a0d6fd 100644
--- a/drivers/net/ixgbe/ixgbe_testpmd.c
+++ b/drivers/net/ixgbe/ixgbe_testpmd.c
@@ -122,6 +122,7 @@  cmd_set_vf_split_drop_en_parsed(void *parsed_result,
 	struct cmd_vf_split_drop_en_result *res = parsed_result;
 	int ret = -ENOTSUP;
 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
 		return;
@@ -141,7 +142,9 @@  cmd_set_vf_split_drop_en_parsed(void *parsed_result,
 		fprintf(stderr, "not supported on port %d\n", res->port_id);
 		break;
 	default:
-		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
+		if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret);
+		fprintf(stderr, "programming error: (%s)\n", errmsg);
 	}
 }
 
@@ -215,6 +218,7 @@  cmd_set_macsec_offload_on_parsed(void *parsed_result,
 	int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
 	int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
 	struct rte_eth_dev_info dev_info;
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN))
 		return;
@@ -243,7 +247,9 @@  cmd_set_macsec_offload_on_parsed(void *parsed_result,
 		fprintf(stderr, "not supported on port %d\n", port_id);
 		break;
 	default:
-		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
+		if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret);
+		fprintf(stderr, "programming error: (%s)\n", errmsg);
 	}
 }
 
@@ -300,6 +306,7 @@  cmd_set_macsec_offload_off_parsed(void *parsed_result,
 	int ret = -ENOTSUP;
 	struct rte_eth_dev_info dev_info;
 	portid_t port_id = res->port_id;
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN))
 		return;
@@ -327,7 +334,9 @@  cmd_set_macsec_offload_off_parsed(void *parsed_result,
 		fprintf(stderr, "not supported on port %d\n", port_id);
 		break;
 	default:
-		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
+		if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret);
+		fprintf(stderr, "programming error: (%s)\n", errmsg);
 	}
 }
 
@@ -386,6 +395,7 @@  cmd_set_macsec_sc_parsed(void *parsed_result,
 	struct cmd_macsec_sc_result *res = parsed_result;
 	int ret = -ENOTSUP;
 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	ret = is_tx ?
 		rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
@@ -402,7 +412,9 @@  cmd_set_macsec_sc_parsed(void *parsed_result,
 		fprintf(stderr, "not supported on port %d\n", res->port_id);
 		break;
 	default:
-		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
+		if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret);
+		fprintf(stderr, "programming error: (%s)\n", errmsg);
 	}
 }
 
@@ -471,6 +483,7 @@  cmd_set_macsec_sa_parsed(void *parsed_result,
 	struct cmd_macsec_sa_result *res = parsed_result;
 	int ret = -ENOTSUP;
 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	uint8_t key[16] = { 0 };
 	uint8_t xdgt0;
 	uint8_t xdgt1;
@@ -510,7 +523,9 @@  cmd_set_macsec_sa_parsed(void *parsed_result,
 		fprintf(stderr, "not supported on port %d\n", res->port_id);
 		break;
 	default:
-		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
+		if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret);
+		fprintf(stderr, "programming error: (%s)\n", errmsg);
 	}
 }
 
@@ -565,6 +580,7 @@  cmd_tc_min_bw_parsed(void *parsed_result,
 	__rte_unused struct cmdline *cl, __rte_unused void *data)
 {
 	struct cmd_vf_tc_bw_result *res = parsed_result;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct rte_port *port;
 	uint8_t tc_num;
 	uint8_t bw[16];
@@ -599,7 +615,9 @@  cmd_tc_min_bw_parsed(void *parsed_result,
 		fprintf(stderr, "function not implemented\n");
 		break;
 	default:
-		fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
+		if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret);
+		fprintf(stderr, "programming error: (%s)\n", errmsg);
 	}
 }