From: Egor Shestakov <vedingrot@gmail.com>
To: linux-fsdevel@vger.kernel.org
Subject: [BUG] f2fs-tools: fsck infinite loop in options parsing
Date: Wed, 27 Aug 2025 21:20:26 +0700 [thread overview]
Message-ID: <aK8UKm+kAM+1AZow@laptop> (raw)
Hi!
I found a bug in the fsck.f2fs that cause infinite loop in
f2fs_parse_options(). To reproduce it you can call program with a
'-py' united options combination, but when it's separate '-p -y'
works well. Simply execute `./f2fs.fsck -py` to catch the bug.
Buggy part of a fsck/main.c code (unchanged since 2018):
> case 'p':
> /* preen mode has different levels:
> * 0: default level, the same as -a
> * 1: check meta
> * 2: same as 0, but will skip some
> * check for old kernel
> */
> if (optarg[0] == '-' || !is_digits(optarg) ||
> optind == argc) {
> MSG(0, "Info: Use default preen mode\n");
> c.preen_mode = PREEN_MODE_0;
> c.auto_fix = 1;
> optind--;
> break;
> }
The bug occurs when a case 'p' match and after it there is not
suitable argument so a decrement optind-- happened. Since the
option '-p' united with its argument a getopt increments optind
only by one, not by two, as expected. Therefore it enters to
infinite loop.
I couldn't find good solution. Changing a preen level options
semantic is impossible because breaks many scripts, for example
in initrd. Possible solution is use a two colons in optstring
that means optinal argument, but this is a GNU extension, so not
all standard libraries support it, in particular Musl.
--
Egor Shestakov
vedingrot ascii(0x40) gmail ascii(0x2E) com
reply other threads:[~2025-08-27 14:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=aK8UKm+kAM+1AZow@laptop \
--to=vedingrot@gmail.com \
--cc=linux-fsdevel@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