[v5,35/52] net/ice: replace strerror with reentrant version

Message ID 20241104111037.3632161-36-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/ice/ice_testpmd.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/net/ice/ice_testpmd.c b/drivers/net/ice/ice_testpmd.c
index 98c02d68c6..03ec3e0adc 100644
--- a/drivers/net/ice/ice_testpmd.c
+++ b/drivers/net/ice/ice_testpmd.c
@@ -38,6 +38,7 @@  cmd_ddp_dump_parsed(void *parsed_result,
 		    __rte_unused void *data)
 {
 	struct cmd_ddp_dump_result *res = parsed_result;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	uint8_t *buff;
 	uint32_t size;
 	int ret = -ENOTSUP;
@@ -59,9 +60,11 @@  cmd_ddp_dump_parsed(void *parsed_result,
 				"dump DDP runtime configure.\n");
 			break;
 		default:
+			if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret);
 			fprintf(stderr,
 				"Failed to dump DDP runtime configure,"
-				" error: (%s)\n", strerror(-ret));
+				" error: (%s)\n", errmsg);
 		}
 	}
 	free(buff);
@@ -105,6 +108,7 @@  cmd_ddp_dump_switch_parsed(void *parsed_result,
 			   __rte_unused void *data)
 {
 	struct cmd_ddp_dump_switch_result *res = parsed_result;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	uint8_t *buff;
 	uint32_t size;
 	int ret = -ENOTSUP;
@@ -126,9 +130,11 @@  cmd_ddp_dump_switch_parsed(void *parsed_result,
 				"dump DDP switch runtime configure.\n");
 			break;
 		default:
+			if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret);
 			fprintf(stderr,
 				"Failed to dump DDP switch runtime configure,"
-				" error: (%s)\n", strerror(-ret));
+				" error: (%s)\n", rte_strerror(-ret));
 		}
 	}
 	free(buff);