mirror of
https://gitee.com/openharmony/third_party_f2fs-tools
synced 2024-11-23 10:10:00 +00:00
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>
This commit is contained in:
parent
cd0f88bc6e
commit
25ab476727
@ -469,7 +469,8 @@ static int f2fs_prepare_super_block(void)
|
|||||||
|
|
||||||
total_zones = get_sb(segment_count) / (c.segs_per_zone) -
|
total_zones = get_sb(segment_count) / (c.segs_per_zone) -
|
||||||
total_meta_zones;
|
total_meta_zones;
|
||||||
|
if (total_zones == 0)
|
||||||
|
goto too_small;
|
||||||
set_sb(section_count, total_zones * c.secs_per_zone);
|
set_sb(section_count, total_zones * c.secs_per_zone);
|
||||||
|
|
||||||
set_sb(segment_count_main, get_sb(section_count) * c.segs_per_sec);
|
set_sb(segment_count_main, get_sb(section_count) * c.segs_per_sec);
|
||||||
@ -499,8 +500,7 @@ static int f2fs_prepare_super_block(void)
|
|||||||
c.sector_size < zone_align_start_offset) ||
|
c.sector_size < zone_align_start_offset) ||
|
||||||
(get_sb(segment_count_main) - NR_CURSEG_TYPE) <
|
(get_sb(segment_count_main) - NR_CURSEG_TYPE) <
|
||||||
c.reserved_segments) {
|
c.reserved_segments) {
|
||||||
MSG(0, "\tError: Device size is not sufficient for F2FS volume\n");
|
goto too_small;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.vol_uuid) {
|
if (c.vol_uuid) {
|
||||||
@ -614,6 +614,10 @@ static int f2fs_prepare_super_block(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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)
|
static int f2fs_init_sit_area(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user