From: Integral <integral@archlinuxcn.org>
To: Kent Overstreet <kent.overstreet@linux.dev>,
Kent Overstreet <kent.overstreet@gmail.com>
Cc: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org,
Integral <integral@archlinuxcn.org>
Subject: [PATCH] bcachefs: return early for negative values when parsing BCH_OPT_UINT
Date: Sun, 6 Apr 2025 21:59:30 +0800 [thread overview]
Message-ID: <20250406135929.178583-2-integral@archlinuxcn.org> (raw)
Currently, when a negative integer is passed as an argument, the error
message incorrectly states "too big" due to the value being cast to an
unsigned integer:
> bcachefs format --block_size=-1 bcachefs.img
invalid option: block_size: too big (max 65536)
To resolve this issue, return early for negative values before calling
bch2_opt_validate().
Signed-off-by: Integral <integral@archlinuxcn.org>
---
fs/bcachefs/opts.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c
index e64777ecf44f..31f90c177c6c 100644
--- a/fs/bcachefs/opts.c
+++ b/fs/bcachefs/opts.c
@@ -360,9 +360,15 @@ int bch2_opt_parse(struct bch_fs *c,
return -EINVAL;
}
- ret = opt->flags & OPT_HUMAN_READABLE
- ? bch2_strtou64_h(val, res)
- : kstrtou64(val, 10, res);
+ if (*val != '-') {
+ ret = opt->flags & OPT_HUMAN_READABLE
+ ? bch2_strtou64_h(val, res)
+ : kstrtou64(val, 10, res);
+ } else {
+ prt_printf(err, "%s: must be a non-negative number", opt->attr.name);
+ return -EINVAL;
+ }
+
if (ret < 0) {
if (err)
prt_printf(err, "%s: must be a number",
--
2.49.0
next reply other threads:[~2025-04-06 14:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-06 13:59 Integral [this message]
2025-04-06 14:11 ` [PATCH] bcachefs: return early for negative values when parsing BCH_OPT_UINT Kent Overstreet
2025-04-06 14:53 ` [PATCH v2] bcachefs: early return " Integral
2025-04-06 17:26 ` Kent Overstreet
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=20250406135929.178583-2-integral@archlinuxcn.org \
--to=integral@archlinuxcn.org \
--cc=kent.overstreet@gmail.com \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcachefs@vger.kernel.org \
--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