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.
Fixes: a7a05af4a1ea ("netlink: add netlink handler for sfeatures (-K)")
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
diff --git a/netlink/features.c b/netlink/features.c
index 5711ff4..1a8c2f5 100644
--- a/netlink/features.c
+++ b/netlink/features.c
@@ -275,9 +275,11 @@
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;
}