From: Jan Kara Date: Tue, 19 Jun 2018 03:19:27 +0000 (-0400) Subject: libext2fs: fix possible inode count overflow when creating fs X-Git-Tag: v1.44.3-rc1~64 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=1071df83f969d64dd6dedf4f697da02e0889bf40;p=tools%2Fe2fsprogs.git libext2fs: fix possible inode count overflow when creating fs If blocks count is exactly 1<<32, then the code computing number of inode count in ext2fs_initialize() will overflow and set number of inodes to 0 (which will be later fixed up to EXT2_FIRST_INODE(super)+1). Fix the off-by-one bug in the check. Reviewed-by: Andreas Dilger Signed-off-by: Jan Kara Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index dbe798b..e1eff22 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -295,7 +295,7 @@ retry: i = fs->blocksize >= 4096 ? 1 : 4096 / fs->blocksize; if (ext2fs_has_feature_64bit(super) && - (ext2fs_blocks_count(super) / i) > (1ULL << 32)) + (ext2fs_blocks_count(super) / i) >= (1ULL << 32)) set_field(s_inodes_count, ~0U); else set_field(s_inodes_count, ext2fs_blocks_count(super) / i);