From 71482c2da0d6493fa8fbbce3b95639b515f867e0 Mon Sep 17 00:00:00 2001
From: arbala <bala.arunachalam@iopsys.eu>
Date: Tue, 13 May 2025 11:32:09 +0200
Subject: [PATCH] add checks for null pointer dereference

---
 src/agent.c      | 11 ++++++++++-
 src/assoc_ctrl.c |  5 +++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/agent.c b/src/agent.c
index ebf203f19..a780ecf9c 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -1805,6 +1805,15 @@ static int agent_modify_assoc_status(struct netif_ap *ap, bool allowed)
 {
 	int ret = 0;
 
+	if (!ap) {
+		trace("%s: ap is NULL\n", __func__);
+		return -EINVAL;
+	}
+	if (!ap->cfg) {
+		trace("%s: ap has NULL cfg\n", __func__);
+		return -EINVAL;
+	}
+
 	ret = wifi_set_ap_mbo_association_mode(ap->ifname, !allowed);
 	if (!ret) {
 		ap->cfg->disallow_assoc = !allowed;
@@ -7109,7 +7118,7 @@ static void agent_fetch_ap_stats(struct agent *a)
 
 			snprintf(objname, sizeof(objname), "wifi.ap.%s", ap->ifname);
 #if (EASYMESH_VERSION >= 6)
-			if (ap->cfg->mld_id) {
+			if (ap->cfg && ap->cfg->mld_id) {
 				struct mld_credential *mldcred;
 
 				mldcred = agent_get_mld_credential_by_id(&a->cfg,
diff --git a/src/assoc_ctrl.c b/src/assoc_ctrl.c
index 3fd867c20..29d0a26f9 100644
--- a/src/assoc_ctrl.c
+++ b/src/assoc_ctrl.c
@@ -243,6 +243,11 @@ int assoc_ctrl_sync_from_config(struct agent *a, struct netif_ap *ap)
 	int num_sta = 0;
 	int ret = 0;
 
+	if (!ap || !ap->cfg) {
+		trace("%s: ap has NULL cfg\n", __func__);
+		return -EINVAL;
+	}
+
 	/* 1. Add STAs missing in runtime list */
 	list_for_each_entry(x, &ap->cfg->assoc_ctrllist, list) {
 		memcpy(stalist[num_sta++], x->macaddr, 6);
-- 
GitLab