[PATCH v2 02/44] ethdev: fix segment fault when parse args

Chengwen Feng fengchengwen at huawei.com
Mon Mar 20 10:20:28 CET 2023


The rte_kvargs_process() was used to parse KV pairs, it also supports
to parse 'only keys' (e.g. socket_id) type. And the callback function
parameter 'value' is NULL when parsed 'only keys'.

This patch fixes segment fault when parse args with 'only keys'
(e.g. 'mac,representor').

Fixes: c10cdce180a6 ("ethdev: support MAC address as iterator filter")
Fixes: a7d3c6271d55 ("ethdev: support representor id as iterator filter")
Cc: stable at dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen at huawei.com>
---
 lib/ethdev/rte_class_eth.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/ethdev/rte_class_eth.c b/lib/ethdev/rte_class_eth.c
index b61dae849d..b9fc25348b 100644
--- a/lib/ethdev/rte_class_eth.c
+++ b/lib/ethdev/rte_class_eth.c
@@ -46,6 +46,9 @@ eth_mac_cmp(const char *key __rte_unused,
 	struct rte_eth_dev_info dev_info;
 	uint32_t index;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	/* Parse devargs MAC address. */
 	if (rte_ether_unformat_addr(value, &mac) < 0)
 		return -1; /* invalid devargs value */
@@ -72,6 +75,9 @@ eth_representor_cmp(const char *key __rte_unused,
 	if ((data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0)
 		return -1; /* not a representor port */
 
+	if (value == NULL)
+		return -EINVAL;
+
 	/* Parse devargs representor values. */
 	values = strdup(value);
 	if (values == NULL)
-- 
2.17.1



More information about the dev mailing list