summaryrefslogtreecommitdiff
path: root/backport-fix-possible-NULL-dereference-in-fec_mode_walk.patch
blob: dc3f4f7ed7e2e416e947982332f7c838efd90cc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
From 33fffbbdc12d71b3bb23acd04b97ce1b485f3c60 Mon Sep 17 00:00:00 2001
From: AntonMoryakov <ant.v.moryakov@gmail.com>
Date: Sun, 18 May 2025 16:18:18 +0300
Subject: fec: fix possible NULL dereference in fec_mode_walk()

Static analyzer (Svace) reported a possible null pointer dereference
in fec_mode_walk(), where the 'name' pointer is passed to print_string()
without checking for NULL.

Although some callers check the return value of get_string(), others
(e.g., walk_bitset()) do not. This patch adds an early NULL check
to avoid dereferencing a null pointer.

This resolves:
DEREF_OF_NULL.EX.COND: json_print.c:142 via fec.c

Found by Svace static analysis tool.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
---
 netlink/fec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/netlink/fec.c b/netlink/fec.c
index 6027dc0..ed100d7 100644
--- a/netlink/fec.c
+++ b/netlink/fec.c
@@ -27,6 +27,8 @@ fec_mode_walk(unsigned int idx, const char *name, bool val, void *data)
 
 	if (!val)
 		return;
+	if (!name)
+		return;
 	if (empty)
 		*empty = false;
 
-- 
2.23.0