[v2,17/44] net/ice: fix segment fault when parse devargs

Message ID 20230320092110.37295-18-fengchengwen@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers
Series fix segment fault when parse args |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

fengchengwen March 20, 2023, 9:20 a.m. UTC
  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 input args with 'only keys'.

Fixes: 9e984bc53bc9 ("net/ice: add option to disable ACL engine in DCF")
Fixes: 7564d5509611 ("net/ice: add DCF hardware initialization")
Fixes: 603beeb970b5 ("net/ice: add safe mode devarg")
Fixes: 79d559de896b ("net/ice: add option for setting HW debug mask")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/net/ice/ice_dcf_ethdev.c | 6 ++++++
 drivers/net/ice/ice_ethdev.c     | 6 ++++++
 2 files changed, 12 insertions(+)
  

Patch

diff --git a/drivers/net/ice/ice_dcf_ethdev.c b/drivers/net/ice/ice_dcf_ethdev.c
index dcbf2af5b0..9fe712ebd1 100644
--- a/drivers/net/ice/ice_dcf_ethdev.c
+++ b/drivers/net/ice/ice_dcf_ethdev.c
@@ -1933,6 +1933,9 @@  static int
 ice_dcf_engine_disabled_handler(__rte_unused const char *key,
 			  const char *value, __rte_unused void *opaque)
 {
+	if (value == NULL)
+		return -EINVAL;
+
 	if (strcmp(value, "off"))
 		return -1;
 
@@ -1943,6 +1946,9 @@  static int
 ice_dcf_cap_check_handler(__rte_unused const char *key,
 			  const char *value, __rte_unused void *opaque)
 {
+	if (value == NULL)
+		return -EINVAL;
+
 	if (strcmp(value, "dcf"))
 		return -1;
 
diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c
index 9a88cf9796..0917d20515 100644
--- a/drivers/net/ice/ice_ethdev.c
+++ b/drivers/net/ice/ice_ethdev.c
@@ -1887,6 +1887,9 @@  parse_bool(const char *key, const char *value, void *args)
 	char *end;
 	int num;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	num = strtoul(value, &end, 10);
 
 	if (num != 0 && num != 1) {
@@ -1906,6 +1909,9 @@  parse_u64(const char *key, const char *value, void *args)
 	u64 *num = (u64 *)args;
 	u64 tmp;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	errno = 0;
 	tmp = strtoull(value, NULL, 16);
 	if (errno) {