From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH 3/3] fsck.f2fs: fix to use strncmp to avoid out-of-boundary access
Date: Fri, 11 Jul 2025 15:45:51 +0800 [thread overview]
Message-ID: <20250711074551.216069-3-chao@kernel.org> (raw)
In-Reply-To: <20250711074551.216069-1-chao@kernel.org>
Otherwise, if length of main device path is equal to MAX_PATH_LEN,
it will trigger assert() as below:
[ASSERT] (init_sb_info:1264) !strcmp((char *)sb->devs[i].path, (char *)c.devices[i].path)
This is because there is no null character in the end of devcie
path string, result in out-of-boundary access in devs.path[].
Let's use strncmp instead of strcmp to compare device path to fix
this issue.
Signed-off-by: Chao Yu <chao@kernel.org>
---
fsck/mount.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fsck/mount.c b/fsck/mount.c
index dbbeb56..a1c4cbb 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -1261,8 +1261,9 @@ int init_sb_info(struct f2fs_sb_info *sbi)
if (get_device_info(i))
ASSERT(0);
} else if (c.func != INJECT) {
- if (strcmp((char *)sb->devs[i].path,
- (char *)c.devices[i].path)) {
+ if (strncmp((char *)sb->devs[i].path,
+ (char *)c.devices[i].path,
+ MAX_PATH_LEN)) {
MSG(0, "paths mismatch: %s, %s\n",
(char *)sb->devs[i].path,
(char *)c.devices[i].path);
--
2.49.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
prev parent reply other threads:[~2025-07-11 7:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-11 7:45 [f2fs-dev] [PATCH 1/3] fsck.f2fs: allow to print more infos before assert() in init_sb_info() Chao Yu via Linux-f2fs-devel
2025-07-11 7:45 ` [f2fs-dev] [PATCH 2/3] mkfs.f2fs: fix to limit length of main device path in f2fs_parse_options() Chao Yu via Linux-f2fs-devel
2025-07-11 7:45 ` Chao Yu via Linux-f2fs-devel [this message]
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=20250711074551.216069-3-chao@kernel.org \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=chao@kernel.org \
--cc=jaegeuk@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