diff mbox series

wifi: cfg80211: Fix potential NULL dereference in test_cfg80211_parse_colocated_ap()

Message ID 20241115052525.14554-1-zichenxie0106@gmail.com (mailing list archive)
State Superseded
Delegated to: Johannes Berg
Headers show
Series wifi: cfg80211: Fix potential NULL dereference in test_cfg80211_parse_colocated_ap() | expand

Commit Message

Gax-c Nov. 15, 2024, 5:25 a.m. UTC
From: Zichen Xie <zichenxie0106@gmail.com>

kunit_kzalloc() may return NULL, dereferencing it without NULL check may
lead to NULL dereference.
Add a NULL check for ies.

Fixes: 45d43937a44c ("wifi: cfg80211: add a kunit test for 6 GHz colocated AP parsing")
Signed-off-by: Zichen Xie <zichenxie0106@gmail.com>
---
 net/wireless/tests/scan.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Johannes Berg Nov. 15, 2024, 6:07 a.m. UTC | #1
On Thu, 2024-11-14 at 23:25 -0600, Gax-c wrote:
> From: Zichen Xie <zichenxie0106@gmail.com>
> 
> kunit_kzalloc() may return NULL, dereferencing it without NULL check may
> lead to NULL dereference.
> Add a NULL check for ies.
> 

Let's prefix with "wifi: cfg80211: tests: " for those, I think?

johannes
diff mbox series

Patch

diff --git a/net/wireless/tests/scan.c b/net/wireless/tests/scan.c
index 9f458be71659..79a99cf5e892 100644
--- a/net/wireless/tests/scan.c
+++ b/net/wireless/tests/scan.c
@@ -810,6 +810,8 @@  static void test_cfg80211_parse_colocated_ap(struct kunit *test)
 		skb_put_data(input, "123", 3);
 
 	ies = kunit_kzalloc(test, struct_size(ies, data, input->len), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, ies);
+
 	ies->len = input->len;
 	memcpy(ies->data, input->data, input->len);