Skip to contentSkip to conversation

fsck.f2fs: fix to avoid using uninitialized buffer

PATCH In review Chao Yu via Linux-f2fs-devel 2 participants 3 messages Jun 3, 2025

lore
Share & tools
lore
#0 lore raw

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.

Cc Daeho Jeong <[email protected]>
---
 fsck/fsck.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fsck/fsck.c +6 -1
index 4d05e1b..bb39f8b 100644
@@ -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
Reviewed-by Chao Yu on v1 1/1
#1 lore raw
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 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 <[email protected]>
---
 fsck/fsck.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fsck/fsck.c +6 -2
index 4d05e1b..bb39f8b 100644
@@ -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

Reviewed-by
#2 lore raw
Quoted 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 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 <[email protected]>
---
 fsck/fsck.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fsck/fsck.c +6 -1
index 4d05e1b..bb39f8b 100644
@@ -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 -1
        if (!ret)
--

2.40.1

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