[RFC] kvargs: don't pass parse handler a NULL pointer
Stephen Hemminger
stephen at networkplumber.org
Tue Oct 31 21:58:32 CET 2023
There is class of problems in current DPDK where rte_kvargs
is used a key/value pair is passed without an associated value.
Currently, this can cause a NULL dereference in the rte_kvargs_process
handler.
Reported-by: Chengwen Feng <fengchengwen at huawei.com>
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
lib/kvargs/rte_kvargs.c | 3 +++
lib/kvargs/rte_kvargs.h | 3 +++
2 files changed, 6 insertions(+)
diff --git a/lib/kvargs/rte_kvargs.c b/lib/kvargs/rte_kvargs.c
index c77bb82feb..5481f58584 100644
--- a/lib/kvargs/rte_kvargs.c
+++ b/lib/kvargs/rte_kvargs.c
@@ -185,6 +185,9 @@ rte_kvargs_process(const struct rte_kvargs *kvlist,
for (i = 0; i < kvlist->count; i++) {
pair = &kvlist->pairs[i];
if (key_match == NULL || strcmp(pair->key, key_match) == 0) {
+ if (pair->value == NULL)
+ return -1;
+
if ((*handler)(pair->key, pair->value, opaque_arg) < 0)
return -1;
}
diff --git a/lib/kvargs/rte_kvargs.h b/lib/kvargs/rte_kvargs.h
index 4900b750bc..fd9a3238f0 100644
--- a/lib/kvargs/rte_kvargs.h
+++ b/lib/kvargs/rte_kvargs.h
@@ -178,6 +178,9 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist,
* handler function with the for a given arg_name passing the value on the
* dictionary for that key and a given extra argument.
*
+ * If no value was specified with the given key, then this
+ * function will return -1 and the handlere will not be called.
+ *
* @param kvlist
* The rte_kvargs structure. No error if NULL.
* @param key_match
--
2.41.0
More information about the dev
mailing list