diff options
author | Eric Biggers <ebiggers@google.com> | 2022-08-15 21:48:32 -0700 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2022-08-19 16:22:36 -0700 |
commit | 9b7a4c5d4f62407ff997a6c00d81369f9dc15c09 (patch) | |
tree | 9f78837a05c20affa75643abe950374817657b37 | |
parent | 6148db344eb25b23a7cbde36d026011cd15b6143 (diff) | |
download | f2fs-tools-9b7a4c5d4f62407ff997a6c00d81369f9dc15c09.tar.gz |
mkfs.f2fs: catch total_zones=0 instead of crashing
Cleanly report an error instead of dividing by 0 (causing a floating
point exception) in the following case:
truncate -s 16M img && mkfs.f2fs img
Note that this is a minimal fix; it appears that overly-small images
still cause various integer overflows in f2fs_prepare_super_block().
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r-- | mkfs/f2fs_format.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c index 7cd5815..40ac589 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -467,7 +467,8 @@ static int f2fs_prepare_super_block(void) total_zones = get_sb(segment_count) / (c.segs_per_zone) - total_meta_zones; - + if (total_zones == 0) + goto too_small; set_sb(section_count, total_zones * c.secs_per_zone); set_sb(segment_count_main, get_sb(section_count) * c.segs_per_sec); @@ -497,8 +498,7 @@ static int f2fs_prepare_super_block(void) c.sector_size < zone_align_start_offset) || (get_sb(segment_count_main) - NR_CURSEG_TYPE) < c.reserved_segments) { - MSG(0, "\tError: Device size is not sufficient for F2FS volume\n"); - return -1; + goto too_small; } if (c.vol_uuid) { @@ -612,6 +612,10 @@ static int f2fs_prepare_super_block(void) } return 0; + +too_small: + MSG(0, "\tError: Device size is not sufficient for F2FS volume\n"); + return -1; } static int f2fs_init_sit_area(void) |