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 75BE745C76; Mon, 4 Nov 2024 12:13:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6147B410E8; Mon, 4 Nov 2024 12:11:15 +0100 (CET) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by mails.dpdk.org (Postfix) with ESMTP id 7153640E38 for ; Mon, 4 Nov 2024 12:10:45 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Xhpcx5QXVz2Fbsg; Mon, 4 Nov 2024 19:09:05 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id 46E6B1401F3; 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 34/52] net/i40e: replace strerror with reentrant version Date: Mon, 4 Nov 2024 19:10:19 +0800 Message-ID: <20241104111037.3632161-35-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/i40e/i40e_testpmd.c | 109 +++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 23 deletions(-) diff --git a/drivers/net/i40e/i40e_testpmd.c b/drivers/net/i40e/i40e_testpmd.c index b6ef5d6e42..ef910c1cbc 100644 --- a/drivers/net/i40e/i40e_testpmd.c +++ b/drivers/net/i40e/i40e_testpmd.c @@ -33,6 +33,7 @@ cmd_queue_region_parsed(void *parsed_result, int ret = -ENOTSUP; struct rte_pmd_i40e_queue_region_conf region_conf; enum rte_pmd_i40e_queue_region_op op_type; + char errmsg[RTE_STRERR_BUFSIZE]; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) return; @@ -52,8 +53,10 @@ cmd_queue_region_parsed(void *parsed_result, fprintf(stderr, "function not implemented or supported\n"); break; default: + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); fprintf(stderr, "queue region config error: (%s)\n", - strerror(-ret)); + errmsg); } } @@ -128,6 +131,7 @@ cmd_region_flowtype_parsed(void *parsed_result, int ret = -ENOTSUP; struct rte_pmd_i40e_queue_region_conf region_conf; enum rte_pmd_i40e_queue_region_op op_type; + char errmsg[RTE_STRERR_BUFSIZE]; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) return; @@ -147,8 +151,10 @@ cmd_region_flowtype_parsed(void *parsed_result, fprintf(stderr, "function not implemented or supported\n"); break; default: + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); fprintf(stderr, "region flowtype config error: (%s)\n", - strerror(-ret)); + errmsg); } } @@ -214,6 +220,7 @@ cmd_user_priority_region_parsed(void *parsed_result, int ret = -ENOTSUP; struct rte_pmd_i40e_queue_region_conf region_conf; enum rte_pmd_i40e_queue_region_op op_type; + char errmsg[RTE_STRERR_BUFSIZE]; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) return; @@ -232,8 +239,10 @@ cmd_user_priority_region_parsed(void *parsed_result, fprintf(stderr, "function not implemented or supported\n"); break; default: + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); fprintf(stderr, "user_priority region config error: (%s)\n", - strerror(-ret)); + errmsg); } } @@ -299,6 +308,7 @@ cmd_flush_queue_region_parsed(void *parsed_result, int ret = -ENOTSUP; struct rte_pmd_i40e_queue_region_conf region_conf; enum rte_pmd_i40e_queue_region_op op_type; + char errmsg[RTE_STRERR_BUFSIZE]; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) return; @@ -319,8 +329,10 @@ cmd_flush_queue_region_parsed(void *parsed_result, fprintf(stderr, "function not implemented or supported\n"); break; default: + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); fprintf(stderr, "queue region config flush error: (%s)\n", - strerror(-ret)); + errmsg); } } @@ -413,6 +425,7 @@ cmd_show_queue_region_info_parsed(void *parsed_result, int ret = -ENOTSUP; struct rte_pmd_i40e_queue_regions rte_pmd_regions; enum rte_pmd_i40e_queue_region_op op_type; + char errmsg[RTE_STRERR_BUFSIZE]; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) return; @@ -432,8 +445,10 @@ cmd_show_queue_region_info_parsed(void *parsed_result, fprintf(stderr, "function not implemented or supported\n"); break; default: + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); fprintf(stderr, "queue region config info show error: (%s)\n", - strerror(-ret)); + errmsg); } } @@ -492,6 +507,7 @@ cmd_flow_director_filter_parsed(void *parsed_result, mapping[RTE_PMD_I40E_FLOW_TYPE_MAX]; struct rte_pmd_i40e_pkt_template_conf conf; uint16_t flow_type = str_to_flowtype(res->flow_type); + char errmsg[RTE_STRERR_BUFSIZE]; uint16_t i, port = res->port_id; uint8_t add; @@ -534,9 +550,11 @@ cmd_flow_director_filter_parsed(void *parsed_result, ret = rte_pmd_i40e_flow_add_del_packet_template(port, &conf, add); - if (ret < 0) - fprintf(stderr, "flow director config error: (%s)\n", - strerror(-ret)); + if (ret < 0) { + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); + fprintf(stderr, "flow director config error: (%s)\n", errmsg); + } close_file(conf.input.packet); } @@ -645,6 +663,7 @@ cmd_set_vf_promisc_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_vf_promisc_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; int ret = -ENOTSUP; __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; @@ -666,7 +685,9 @@ cmd_set_vf_promisc_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); } } @@ -724,6 +745,7 @@ cmd_set_vf_allmulti_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_vf_allmulti_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; int ret = -ENOTSUP; __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; @@ -745,7 +767,9 @@ cmd_set_vf_allmulti_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); } } @@ -803,6 +827,7 @@ cmd_set_vf_broadcast_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_set_vf_broadcast_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; int ret = -ENOTSUP; __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; @@ -825,7 +850,9 @@ cmd_set_vf_broadcast_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); } } @@ -886,6 +913,7 @@ cmd_set_vf_vlan_tag_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_set_vf_vlan_tag_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; int ret = -ENOTSUP; __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; @@ -908,7 +936,9 @@ cmd_set_vf_vlan_tag_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); } } @@ -992,6 +1022,7 @@ cmd_vf_max_bw_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_vf_tc_bw_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; int ret = -ENOTSUP; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) @@ -1013,7 +1044,9 @@ cmd_vf_max_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); } } @@ -1083,6 +1116,7 @@ cmd_vf_tc_min_bw_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_vf_tc_bw_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; uint8_t tc_num; uint8_t bw[16]; int ret = -ENOTSUP; @@ -1108,7 +1142,9 @@ cmd_vf_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); } } @@ -1137,6 +1173,7 @@ cmd_vf_tc_max_bw_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_vf_tc_bw_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; int ret = -ENOTSUP; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) @@ -1158,7 +1195,9 @@ cmd_vf_tc_max_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); } } @@ -1188,6 +1227,7 @@ cmd_strict_link_prio_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_vf_tc_bw_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; int ret = -ENOTSUP; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) @@ -1207,7 +1247,9 @@ cmd_strict_link_prio_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); } } @@ -1912,6 +1954,7 @@ cmd_pctype_mapping_reset_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_pctype_mapping_reset_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; int ret = -ENOTSUP; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) @@ -1928,7 +1971,9 @@ cmd_pctype_mapping_reset_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); } } @@ -1984,6 +2029,7 @@ cmd_pctype_mapping_get_parsed(void *parsed_result, int ret = -ENOTSUP; struct rte_pmd_i40e_flow_type_mapping mapping[RTE_PMD_I40E_FLOW_TYPE_MAX]; + char errmsg[RTE_STRERR_BUFSIZE]; int i, j, first_pctype; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) @@ -2000,7 +2046,9 @@ cmd_pctype_mapping_get_parsed(void *parsed_result, fprintf(stderr, "function not implemented\n"); return; 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); return; } @@ -2085,6 +2133,7 @@ cmd_pctype_mapping_update_parsed(void *parsed_result, unsigned int i; unsigned int nb_item; unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX]; + char errmsg[RTE_STRERR_BUFSIZE]; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) return; @@ -2111,7 +2160,9 @@ cmd_pctype_mapping_update_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); } } @@ -2170,6 +2221,7 @@ cmd_ptype_mapping_get_parsed(void *parsed_result, int ret = -ENOTSUP; int max_ptype_num = 256; struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num]; + char errmsg[RTE_STRERR_BUFSIZE]; uint16_t count; int i; @@ -2191,7 +2243,9 @@ cmd_ptype_mapping_get_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); } if (!ret) { @@ -2257,6 +2311,7 @@ cmd_ptype_mapping_replace_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_ptype_mapping_replace_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; int ret = -ENOTSUP; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) @@ -2280,7 +2335,9 @@ cmd_ptype_mapping_replace_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); } } @@ -2331,6 +2388,7 @@ cmd_ptype_mapping_reset_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_ptype_mapping_reset_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; int ret = -ENOTSUP; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) @@ -2347,7 +2405,9 @@ cmd_ptype_mapping_reset_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); } } @@ -2404,6 +2464,7 @@ cmd_ptype_mapping_update_parsed(void *parsed_result, struct cmd_ptype_mapping_update_result *res = parsed_result; int ret = -ENOTSUP; struct rte_pmd_i40e_ptype_mapping mapping; + char errmsg[RTE_STRERR_BUFSIZE]; if (port_id_is_invalid(res->port_id, ENABLED_WARN)) return; @@ -2427,7 +2488,9 @@ cmd_ptype_mapping_update_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