[v2,16/44] net/iavf: fix segment fault when parse devargs

Message ID 20230320092110.37295-17-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: b14e8a57b9fe ("net/iavf: support quanta size configuration")
Fixes: 4cce7422dd38 ("net/iavf: stop PCI probe in DCF mode")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/net/iavf/iavf_ethdev.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Patch

diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c
index 3196210f2c..654741b71f 100644
--- a/drivers/net/iavf/iavf_ethdev.c
+++ b/drivers/net/iavf/iavf_ethdev.c
@@ -2185,6 +2185,9 @@  parse_u16(__rte_unused const char *key, const char *value, void *args)
 	u16 *num = (u16 *)args;
 	u16 tmp;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	errno = 0;
 	tmp = strtoull(value, NULL, 10);
 	if (errno || !tmp) {
@@ -2815,6 +2818,9 @@  static int
 iavf_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;