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/qede/qede_regs.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
@@ -213,6 +213,7 @@ qede_set_fw_dump_file_name(struct qede_dev *qdev)
static int
qede_write_fwdump(const char *dump_file, void *dump, size_t len)
{
+ char errmsg[RTE_STRERR_BUFSIZE];
int err = 0;
FILE *f;
size_t bytes;
@@ -220,8 +221,10 @@ qede_write_fwdump(const char *dump_file, void *dump, size_t len)
f = fopen(dump_file, "wb+");
if (!f) {
+ if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+ snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
fprintf(stderr, "Can't open file %s: %s\n",
- dump_file, strerror(errno));
+ dump_file, errmsg);
return 1;
}
bytes = fwrite(dump, 1, len, f);
@@ -233,8 +236,10 @@ qede_write_fwdump(const char *dump_file, void *dump, size_t len)
}
if (fclose(f)) {
+ if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+ snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
fprintf(stderr, "Can't close file %s: %s\n",
- dump_file, strerror(errno));
+ dump_file, errmsg);
err = 1;
}