[v2,07/44] net/af_xdp: fix segment fault when parse devargs

Message ID 20230320092110.37295-8-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: f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
Fixes: 288a85aef192 ("net/af_xdp: enable custom XDP program loading")
Cc: stable@dpdk.org

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

Patch

diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
index 2a20a6960c..519a57aeba 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -1897,6 +1897,9 @@  parse_budget_arg(const char *key __rte_unused,
 	int *i = (int *)extra_args;
 	char *end;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	*i = strtol(value, &end, 10);
 	if (*i < 0 || *i > UINT16_MAX) {
 		AF_XDP_LOG(ERR, "Invalid busy_budget %i, must be >= 0 and <= %u\n",
@@ -1915,6 +1918,9 @@  parse_integer_arg(const char *key __rte_unused,
 	int *i = (int *)extra_args;
 	char *end;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	*i = strtol(value, &end, 10);
 	if (*i < 0) {
 		AF_XDP_LOG(ERR, "Argument has to be positive.\n");
@@ -1931,6 +1937,9 @@  parse_name_arg(const char *key __rte_unused,
 {
 	char *name = extra_args;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	if (strnlen(value, IFNAMSIZ) > IFNAMSIZ - 1) {
 		AF_XDP_LOG(ERR, "Invalid name %s, should be less than %u bytes.\n",
 			   value, IFNAMSIZ);
@@ -1949,6 +1958,9 @@  parse_prog_arg(const char *key __rte_unused,
 {
 	char *path = extra_args;
 
+	if (value == NULL)
+		return -EINVAL;
+
 	if (strnlen(value, PATH_MAX) == PATH_MAX) {
 		AF_XDP_LOG(ERR, "Invalid path %s, should be less than %u bytes.\n",
 			   value, PATH_MAX);