fec: fix possible NULL dereference in fec_mode_walk()
Subsystems (2)
PATCH 1/1 fec: fix possible NULL dereference in fec_mode_walk()
From: AntonMoryakov <[email protected]>
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.
--- netlink/fec.c | 2 ++ 1 file changed, 2 insertions(+)
netlink/fec.c +2 -0
@@ -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;
Signature · 1 line
2.34.1
Dne Sun, May 18, 2025 at 04:18:18PM GMT, [email protected] napsal:
Quoted 26 lines
From: AntonMoryakov <[email protected]>
Static analyzer (Svace) reported a possible null pointer dereference in
fec_mode_walk(), where the 'name' pointer is passed toprint_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 viafec.cFound by Svace static analysis tool.
Signed-off-by Anton Moryakov <[email protected]>--- netlink/fec.c | 2 ++ 1 file changed, 2 insertions(+)netlink/fec.c +0
-0
netlink/fec.c fec_mode_walk(unsigned int idx, const char *name, bool val, void *data) · line 34
Quoted 8 lines
netlink/fec.c +2
-0@@ -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;
I'll apply the patch as it makes the code cleaner and safer against future rewrites but I don't think actual null pointer dereference is still possible after your patch "json_print: add NULL check before jsonw_string_field() in print_string()" as it fixes handling both key and value being null in print_string().
Michal
This patch was applied to ethtool/ethtool.git (master) by Michal Kubecek <[email protected]>:
Hello:
This patch was applied to ethtool/ethtool.git (master) by Michal Kubecek <[email protected]>:
Quoted 11 lines · On Sun, 18 May 2025 16:18:18 +0300 you wrote:
From: AntonMoryakov <[email protected]>
Static analyzer (Svace) reported a possible null pointer dereference in
fec_mode_walk(), where the 'name' pointer is passed toprint_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.[...]
Here is the summary with links:
- fec: fix possible NULL dereference in fec_mode_walk()
https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/commit/?id=33fffbbdc12d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html