[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250709104120.74112-1-ant.v.moryakov@gmail.com>
Date: Wed, 9 Jul 2025 13:41:20 +0300
From: Anton Moryakov <ant.v.moryakov@...il.com>
To: mkubecek@...e.cz
Cc: netdev@...r.kernel.org,
Anton Moryakov <ant.v.moryakov@...il.com>
Subject: [PATCH] ethtool: fix potential NULL pointer dereference in find_option
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@...il.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
Powered by blists - more mailing lists