fsck.f2fs: fix to avoid using uninitialized buffer
PATCH 1/1 fsck.f2fs: fix to avoid using uninitialized buffer
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.
--- fsck/fsck.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fsck/fsck.c +6 -1
@@ -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)
Signature · 8 lines
2.40.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 48 lines · On Tue, Jun 3, 2025 at 12:29 AM Chao Yu via Linux-f2fs-devel…
fsck.c: In function ‘chk_and_fix_wp_with_sit’:
fsck.c:3529:17: error: variable-sized object may not be initialized3529 | char buffer[F2FS_BLKSIZE] = {}; | ^~~~The reason is
F2FS_BLKSIZEmacro is defined w/ c.blksize, let's usecalloc()to allocate zeroed memory to fix this issue.Cc Daeho Jeong <[email protected]>Signed-off-by Chao Yu <[email protected]>--- fsck/fsck.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)fsck/fsck.c +6
-2@@ -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) --
Quoted 2 lines
2.40.1
Thanks,
Quoted 6 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Daeho Jeong
Reviewed-byQuoted 49 lines · Daeho Jeong
Quoted 46 lines · On Tue, Jun 3, 2025 at 12:29 AM Chao Yu via Linux-f2fs-devel…
fsck.c: In function ‘chk_and_fix_wp_with_sit’:
fsck.c:3529:17: error: variable-sized object may not be initialized3529 | char buffer[F2FS_BLKSIZE] = {}; | ^~~~The reason is
F2FS_BLKSIZEmacro is defined w/ c.blksize, let's usecalloc()to allocate zeroed memory to fix this issue.Cc Daeho Jeong <[email protected]>Signed-off-by Chao Yu <[email protected]>--- fsck/fsck.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)fsck/fsck.c +6
-1@@ -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); }
Quoted 8 lines
Quoted 4 lines
fsck/fsck.c +0
-1if (!ret) --2.40.1
Reviewed-by Chao Yu <[email protected]>Thanks,
Oops,
Thanks,
Quoted 7 lines
Quoted 7 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel