From: Nir Lichtman <nir@lichtman.org>
To: jason.wessel@windriver.com, daniel.thompson@linaro.org,
dianders@chromium.org, kgdb-bugreport@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: [PATCH v2] KDB: Fix incorrect treatment of numbers in the CLI
Date: Sat, 19 Oct 2024 20:42:12 +0000 [thread overview]
Message-ID: <20241019204212.GA811391@lichtman.org> (raw)
In-Reply-To: <20241019195715.GA810861@lichtman.org>
Problem: In many cases, KDB treats invalid commands as numbers and
instead of printing a usage error, goes ahead and just prints the number
in hex
Example: This can be demonstrated when typing for example "aaazzz", this
confuses KDB into thinking this is the hexadecimal 0xAAA
Solution: Transition to using kstrtoul instead of simple_strtoul.
This function is more strict with what it treats as a number
and thus solves the issue.
(also better practice as stated in the definition of simple_strtoul).
v2: Removed redundant if condition I put in v1
Signed-off-by: Nir Lichtman <nir@lichtman.org>
---
kernel/debug/kdb/kdb_main.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index f5f7d7fb5936..4cbd5cd26821 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -402,18 +402,15 @@ static void kdb_printenv(void)
*/
int kdbgetularg(const char *arg, unsigned long *value)
{
- char *endp;
unsigned long val;
- val = simple_strtoul(arg, &endp, 0);
- if (endp == arg) {
+ if (kstrtoul(arg, 0, &val) != 0) {
/*
* Also try base 16, for us folks too lazy to type the
* leading 0x...
*/
- val = simple_strtoul(arg, &endp, 16);
- if (endp == arg)
+ if (kstrtoul(arg, 16, &val) != 0)
return KDB_BADINT;
}
--
2.39.2
next prev parent reply other threads:[~2024-10-19 20:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-19 19:57 [PATCH] " Nir Lichtman
2024-10-19 20:42 ` Nir Lichtman [this message]
2024-10-21 17:14 ` [PATCH v2] " Doug Anderson
2024-10-21 19:32 ` Nir Lichtman
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=20241019204212.GA811391@lichtman.org \
--to=nir@lichtman.org \
--cc=daniel.thompson@linaro.org \
--cc=dianders@chromium.org \
--cc=jason.wessel@windriver.com \
--cc=kgdb-bugreport@lists.sourceforge.net \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®