Skip to contentSkip to conversation

netlink: add NULL check for get_string() in features.c

PATCH Applied Anton Moryakov 3 participants 3 messages May 13, 2025 – Jun 10, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netlink: add NULL check for get_string() in features.c

Report of the static analyzer:
Return value of a function 'get_string' is dereferenced at features.c:279 without checking for NULL, but it is usually checked for this function (6/7).

Correct explained:
Added NULL check for get_string() return value before passing to strcmp() to prevent potential NULL pointer dereference. This matches the behavior in other similar code paths where get_string() is used.

Triggers found by static analyzer Svace.

---
 netlink/features.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
netlink/features.c +4 -2
index 5711ff4..1a8c2f5 100644
@@ -275,9 +275,11 @@ static int find_feature(const char *name,
 	const unsigned int count = get_count(feature_names);
 	unsigned int i;
 
-	for (i = 0; i < count; i++)
-		if (!strcmp(name, get_string(feature_names, i)))
+	for (i = 0; i < count; i++) {
+		const char *str = get_string(feature_names, i);
+		if (str && !strcmp(name, str))
 			return i;
+	}
 
 	return -1;
 }
Signature · 1 line
2.30.2
#1 lore raw
Quoted 3 lines · Anton Moryakov

Report of the static analyzer:
Return value of a function 'get_string' is dereferenced at features.c:279 without checking for NULL, but it is usually checked for this function (6/7).

It is a good idea to include the Maintainer in To: otherwise the patch might get lost.

Andrew

#2 lore raw
In reply to Anton Moryakov
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 10 lines · On Tue, 13 May 2025 23:01:28 +0300 you wrote:

Report of the static analyzer:
Return value of a function 'get_string' is dereferenced at features.c:279 without checking for NULL, but it is usually checked for this function (6/7).

Correct explained:
Added NULL check for get_string() return value before passing to strcmp() to prevent potential NULL pointer dereference. This matches the behavior in other similar code paths where get_string() is used.

[...]

Here is the summary with links:
- netlink: add NULL check for get_string() in features.c

    https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/commit/?id=d12a0a7b343e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html