From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: jaegeuk@kernel.org
Cc: Daeho Jeong <daehojeong@google.com>,
linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH] fsck.f2fs: fix to avoid using uninitialized buffer
Date: Tue, 3 Jun 2025 15:26:18 +0800 [thread overview]
Message-ID: <20250603072618.16171-1-chao@kernel.org> (raw)
fsck.c: In function ‘chk_and_fix_wp_with_sit’:
fsck.c:3529:17: error: variable-sized object may not be initialized
3529 | char buffer[F2FS_BLKSIZE] = {};
| ^~~~
The reason is F2FS_BLKSIZE macro is defined w/ c.blksize, let's use
calloc() to allocate zeroed memory to fix this issue.
Cc: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Chao Yu <chao@kernel.org>
---
fsck/fsck.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 4d05e1b..bb39f8b 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -3526,7 +3526,7 @@ static int chk_and_fix_wp_with_sit(int UNUSED(i), void *blkzone, void *opaque)
ret = f2fs_finish_zone(wpd->dev_index, blkz);
if (ret) {
- u8 buffer[F2FS_BLKSIZE] = {};
+ u8 *buffer;
u64 blk_addr = wp_block;
u64 fill_sects = blk_zone_length(blkz) -
(blk_zone_wp_sector(blkz) - blk_zone_sector(blkz));
@@ -3534,6 +3534,9 @@ static int chk_and_fix_wp_with_sit(int UNUSED(i), void *blkzone, void *opaque)
struct seg_entry *se = get_seg_entry(sbi, wp_segno);
enum rw_hint whint = f2fs_io_type_to_rw_hint(se->type);
+ buffer = calloc(F2FS_BLKSIZE, 1);
+ ASSERT(buffer);
+
printf("[FSCK] Finishing zone failed: %s\n", dev->path);
while (len--) {
ret = dev_fill_block(buffer, blk_addr++, whint);
@@ -3542,6 +3545,8 @@ static int chk_and_fix_wp_with_sit(int UNUSED(i), void *blkzone, void *opaque)
break;
}
}
+
+ free(buffer);
}
if (!ret)
--
2.40.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next reply other threads:[~2025-06-03 7:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-03 7:26 Chao Yu via Linux-f2fs-devel [this message]
2025-06-03 16:52 ` [f2fs-dev] [PATCH] fsck.f2fs: fix to avoid using uninitialized buffer Daeho Jeong
2025-06-03 16:54 ` Daeho Jeong
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=20250603072618.16171-1-chao@kernel.org \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=chao@kernel.org \
--cc=daehojeong@google.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.