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(-)
@@ -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);