The function strerror() is insecure in a multi-thread environment.
This patch uses strerror_r() to replace it.

Signed-off-by: Dengdui Huang <huangdeng...@huawei.com>
Acked-by: Chengwen Feng <fengcheng...@huawei.com>
Acked-by: Morten Brørup <m...@smartsharesystems.com>
Acked-by: Huisong Li <lihuis...@huawei.com>
---
 drivers/crypto/caam_jr/caam_jr_uio.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/caam_jr/caam_jr_uio.c 
b/drivers/crypto/caam_jr/caam_jr_uio.c
index 8956f7750d..13e982c9f4 100644
--- a/drivers/crypto/caam_jr/caam_jr_uio.c
+++ b/drivers/crypto/caam_jr/caam_jr_uio.c
@@ -17,6 +17,7 @@
 #include <rte_malloc.h>
 #include <rte_crypto.h>
 #include <rte_security.h>
+#include <rte_errno.h>
 
 #include <caam_jr_config.h>
 #include <caam_jr_hw_specific.h>
@@ -325,6 +326,7 @@ void
 free_job_ring(int uio_fd)
 {
        struct uio_job_ring *job_ring = NULL;
+       char errmsg[RTE_STRERR_BUFSIZE];
        int i;
 
        if (uio_fd == -1)
@@ -353,9 +355,11 @@ free_job_ring(int uio_fd)
 
        /* Unmap the PCI memory resource of device */
        if (munmap(job_ring->register_base_addr, job_ring->map_size)) {
+               if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+                       snprintf(errmsg, sizeof(errmsg), "Unknown error %d", 
errno);
                CAAM_JR_INFO("cannot munmap(%p, 0x%lx): %s",
                        job_ring->register_base_addr,
-                       (unsigned long)job_ring->map_size, strerror(errno));
+                       (unsigned long)job_ring->map_size, errmsg);
        } else
                CAAM_JR_DEBUG("JR UIO memory is unmapped");
 
@@ -409,6 +413,7 @@ uio_job_ring *config_job_ring(void)
 int
 sec_configure(void)
 {
+       char errmsg[RTE_STRERR_BUFSIZE];
        char uio_name[32];
        int config_jr_no = 0, jr_id = -1;
        int uio_minor_number = -1;
@@ -418,8 +423,10 @@ sec_configure(void)
 
        d = opendir(SEC_UIO_DEVICE_SYS_ATTR_PATH);
        if (d == NULL) {
+               if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+                       snprintf(errmsg, sizeof(errmsg), "Unknown error %d", 
errno);
                CAAM_JR_ERR("Error opening directory '%s': %s",
-                       SEC_UIO_DEVICE_SYS_ATTR_PATH, strerror(errno));
+                       SEC_UIO_DEVICE_SYS_ATTR_PATH, errmsg);
                return -1;
        }
 
-- 
2.33.0

Reply via email to