From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0998F45C76; Mon, 4 Nov 2024 12:13:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7E57242789; Mon, 4 Nov 2024 12:11:16 +0100 (CET) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id EA5A040E30 for ; Mon, 4 Nov 2024 12:10:45 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4XhpYZ4Z2qz1JB6J; Mon, 4 Nov 2024 19:06:10 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id 955701401F3; Mon, 4 Nov 2024 19:10:44 +0800 (CST) Received: from localhost.huawei.com (10.50.165.33) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 4 Nov 2024 19:10:44 +0800 From: Dengdui Huang To: CC: , , , , , , , , , , Subject: [PATCH v5 36/52] net/ixgbe: replace strerror with reentrant version Date: Mon, 4 Nov 2024 19:10:21 +0800 Message-ID: <20241104111037.3632161-37-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241104111037.3632161-1-huangdengdui@huawei.com> References: <20231114082539.1858594-1-huangdengdui@huawei.com> <20241104111037.3632161-1-huangdengdui@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500011.china.huawei.com (7.185.36.84) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The function strerror() is insecure in a multi-thread environment. This patch uses strerror_r() to replace it. Signed-off-by: Dengdui Huang Acked-by: Chengwen Feng Acked-by: Morten Brørup Acked-by: Huisong Li --- drivers/net/ixgbe/ixgbe_testpmd.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) 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); } } -- 2.33.0