netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anton Moryakov <ant.v.moryakov@gmail.com>
To: mkubecek@suse.cz
Cc: netdev@vger.kernel.org, Anton Moryakov <ant.v.moryakov@gmail.com>
Subject: [PATCH] ethtool: fix potential NULL pointer dereference in find_option
Date: Wed,  9 Jul 2025 13:41:20 +0300	[thread overview]
Message-ID: <20250709104120.74112-1-ant.v.moryakov@gmail.com> (raw)

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


             reply	other threads:[~2025-07-09 10:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 10:41 Anton Moryakov [this message]
2025-07-21 21:16 ` [PATCH] ethtool: fix potential NULL pointer dereference in find_option Michal Kubecek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250709104120.74112-1-ant.v.moryakov@gmail.com \
    --to=ant.v.moryakov@gmail.com \
    --cc=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).