From: Sheng Yong <shengyong2021@gmail.com>
To: Chao Yu <chao@kernel.org>, jaegeuk@kernel.org
Cc: shengyong1@xiaomi.com, linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [RFC PATCH v2 09/32] inject.f2fs: fix and cleanup parsing numeric options
Date: Mon, 16 Jun 2025 09:49:59 +0800 [thread overview]
Message-ID: <0a5327b6-a74e-4862-8a4c-715e87be64d3@gmail.com> (raw)
In-Reply-To: <de9e00c2-c9c2-4284-af57-ed7e21b07622@kernel.org>
On 6/13/25 14:08, Chao Yu wrote:
> On 2025/6/10 20:37, Sheng Yong wrote:
>> From: Sheng Yong <shengyong1@xiaomi.com>
>>
>> This patch fixes:
>> * parsing hex optarg of --idx option
>> * converting -1 to 0xff...ff of --val option
>> and do a little cleanup of converting string to a long integer.
>>
>> Signed-off-by: Sheng Yong <shengyong1@xiaomi.com>
>> ---
>> fsck/inject.c | 32 +++++++++++++++++---------------
>> 1 file changed, 17 insertions(+), 15 deletions(-)
>>
>> diff --git a/fsck/inject.c b/fsck/inject.c
>> index 96817a806f8f..c879ca99c0d8 100644
>> --- a/fsck/inject.c
>> +++ b/fsck/inject.c
>> @@ -236,8 +236,9 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt)
>> while ((o = getopt_long(argc, argv, option_string,
>> long_opt, NULL)) != EOF) {
>> - long nid, blk;
>> + long long val;
>> + errno = 0;
>> switch (o) {
>> case 1:
>> c.dry_run = 1;
>> @@ -248,18 +249,19 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt)
>> MSG(0, "Info: inject member %s\n", optarg);
>> break;
>> case 3:
>> - if (!is_digits(optarg))
>> - return EWRONG_OPT;
>> - opt->idx = atoi(optarg);
>> - MSG(0, "Info: inject slot index %d\n", opt->idx);
>> + val = strtoll(optarg, &endptr, 0);
>> + if (errno != 0 || val >= UINT_MAX || val < 0 ||
>
> UINT_MAX is a possible injectable value? if so, it need to use "val > UINT_MAX"?
>
Hi, Chao,
For `idx' and sit/nat pack, I think UINT_MAX or -1 will not be used, because these
two values are used to indicate where we do the injection, and UINT_MAX is always
out of boundary of the array.
Thanks,
shengyong
>> + *endptr != '\0')
>> + return -ERANGE;
>> + opt->idx = (unsigned int)val;
>> + MSG(0, "Info: inject slot index %u\n", opt->idx);
>> break;
>> case 4:
>> - opt->val = strtoll(optarg, &endptr, 0);
>> - if (opt->val == LLONG_MAX || opt->val == LLONG_MIN ||
>> - *endptr != '\0')
>> + opt->val = strtoull(optarg, &endptr, 0);
>> + if (errno != 0 || *endptr != '\0')
>> return -ERANGE;
>> MSG(0, "Info: inject value %lld : 0x%llx\n", opt->val,
>> - (unsigned long long)opt->val);
>> + opt->val);
>> break;
>> case 5:
>> opt->str = strdup(optarg);
>> @@ -292,11 +294,11 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt)
>> MSG(0, "Info: inject nat pack %s\n", pack[opt->nat]);
>> break;
>> case 9:
>> - nid = strtol(optarg, &endptr, 0);
>> - if (nid >= UINT_MAX || nid < 0 ||
>> + val = strtoll(optarg, &endptr, 0);
>> + if (errno != 0 || val >= UINT_MAX || val < 0 ||
>> *endptr != '\0')
>> return -ERANGE;
>> - opt->nid = nid;
>> + opt->nid = (nid_t)val;
>> MSG(0, "Info: inject nid %u : 0x%x\n", opt->nid, opt->nid);
>> break;
>> case 10:
>> @@ -308,11 +310,11 @@ int inject_parse_options(int argc, char *argv[], struct inject_option *opt)
>> MSG(0, "Info: inject sit pack %s\n", pack[opt->sit]);
>> break;
>> case 11:
>> - blk = strtol(optarg, &endptr, 0);
>> - if (blk >= UINT_MAX || blk < 0 ||
>> + val = strtoll(optarg, &endptr, 0);
>> + if (errno != 0 || val >= UINT_MAX || val < 0 ||
>> *endptr != '\0')
>> return -ERANGE;
>> - opt->blk = blk;
>> + opt->blk = (block_t)val;
>> MSG(0, "Info: inject blkaddr %u : 0x%x\n", opt->blk, opt->blk);
>> break;
>> case 12:
>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2025-06-16 1:50 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 12:37 [f2fs-dev] [RFC PATCH v2 00/32] f2fs-tools: add testcases Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 01/32] fsck.f2fs: do not finish/reset zone if dry-run is true Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 02/32] f2fs-tools: add option N to answer no for all questions Sheng Yong
2025-06-11 9:22 ` Chao Yu via Linux-f2fs-devel
2025-06-11 9:36 ` Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 03/32] f2fs-tools: cleanup {nid|segno}_in_journal Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 04/32] fsck.f2fs: fix invalidate checkpoint Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 05/32] dump.f2fs: print more info Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 06/32] f2fs-tools: add and export lookup_sit_in_journal Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 07/32] inject.f2fs: fix injecting sit/nat in journal Sheng Yong
2025-06-11 11:42 ` Chao Yu via Linux-f2fs-devel
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 08/32] inject.f2fs: fix injection on zoned device Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 09/32] inject.f2fs: fix and cleanup parsing numeric options Sheng Yong
2025-06-13 6:08 ` Chao Yu via Linux-f2fs-devel
2025-06-16 1:49 ` Sheng Yong [this message]
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 10/32] inject.f2fs: add members in inject_cp Sheng Yong
2025-06-13 7:30 ` Chao Yu via Linux-f2fs-devel
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 11/32] inject.f2fs: add member `feature' in inject_sb Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 12/32] inject.f2fs: add members in inject_node Sheng Yong
2025-06-13 7:38 ` Chao Yu via Linux-f2fs-devel
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 13/32] inject.f2fs: add member `filename' in inject_dentry Sheng Yong
2025-06-13 7:55 ` Chao Yu via Linux-f2fs-devel
2025-06-16 2:01 ` Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 14/32] tests: prepare helper scripts for testcases Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 15/32] tests: add fsck testcase of fixing bad super magic Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 16/32] tests: add fsck testcase of fixing errors recorded in sb Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 17/32] tests: add fsck testcase of fixing cp crc Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 18/32] tests: add fsck testcase of fixing nat entry with invalid ino Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 19/32] tests: add fsck testcase of fixing nat entry with invalid blkaddr Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 20/32] tests: add fsck testcase of fixing sit entry type Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 21/32] tests: add fsck testcase of fixing sit entry vblocks Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 22/32] tests: add fsck testcase of fixing sit entry valid_map Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 23/32] tests: add fsck testcase of fixing sum entry nid Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 24/32] tests: add fsck testcase of fixing sum footer type Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 25/32] tests: add fsck testcase of fixing sum entry ofs_in_node Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 26/32] tests: add fsck testcase of fixing inode invalid i_addr Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 27/32] tests: add fsck testcase of fixing dentry hash code Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 28/32] tests: add fsck testcase of fixing lost dots Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 29/32] tests: add fsck testcase of fixing duplicated dots Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 30/32] tests: add fsck testcase of fixing loop fsync dnodes Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 31/32] tests: add inject testcase of injecting META area Sheng Yong
2025-06-10 12:37 ` [f2fs-dev] [RFC PATCH v2 32/32] tests: add inject testcase of injecting node block Sheng Yong
2025-08-15 10:38 ` [f2fs-dev] [RFC PATCH v2 00/32] f2fs-tools: add testcases Chao Yu via Linux-f2fs-devel
2025-08-15 11:27 ` Sheng Yong
2025-08-16 7:04 ` Chao Yu via Linux-f2fs-devel
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=0a5327b6-a74e-4862-8a4c-715e87be64d3@gmail.com \
--to=shengyong2021@gmail.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=shengyong1@xiaomi.com \
/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).