netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ethtool: fix potential NULL pointer dereference in find_option
@ 2025-07-09 10:41 Anton Moryakov
  2025-07-21 21:16 ` Michal Kubecek
  0 siblings, 1 reply; 2+ messages in thread
From: Anton Moryakov @ 2025-07-09 10:41 UTC (permalink / raw)
  To: mkubecek; +Cc: netdev, Anton Moryakov

Static analyzer reported a possible NULL pointer dereference:

- In main(), 'argp' is dereferenced and passed to find_option()
	without checking if *argp is NULL.
	
- The function find_option() does not validate its input argument,
	which may lead to undefined behavior when using strncmp() or strcspn()
	with a NULL pointer.

This patch adds proper NULL check in find_option() to prevent invalid memory access.
Additionally, it improves robustness by making sure that the input argument
is valid before passing it to find_option().

Found by Svace static analysis tool.

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

diff --git a/ethtool.c b/ethtool.c
index 0513a1a..4250add 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -6395,6 +6395,9 @@ static int show_usage(struct cmd_context *ctx __maybe_unused)
 
 static int find_option(char *arg)
 {
+	if(!arg)
+		return -1;
+		
 	const char *opt;
 	size_t len;
 	int k;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-21 21:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-09 10:41 [PATCH] ethtool: fix potential NULL pointer dereference in find_option Anton Moryakov
2025-07-21 21:16 ` Michal Kubecek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).