* [f2fs-dev] [PATCH] mkfs.f2fs: catch total_zones=0 instead of crashing
@ 2022-08-16 4:48 Eric Biggers
0 siblings, 0 replies; only message in thread
From: Eric Biggers @ 2022-08-16 4:48 UTC (permalink / raw)
To: linux-f2fs-devel
From: Eric Biggers <ebiggers@google.com>
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>
---
mkfs/f2fs_format.c | 10 +++++++---
1 file 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)
base-commit: 6148db344eb25b23a7cbde36d026011cd15b6143
--
2.37.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-08-16 4:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-16 4:48 [f2fs-dev] [PATCH] mkfs.f2fs: catch total_zones=0 instead of crashing Eric Biggers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).