From: Zheng Liu <wenqing.lz@xxxxxxxxxx> There are two bugs need to be fixed, which are about cluster-size. Now the range of cluster-size is from 1024 to 512M bytes. Although with '-C 1024', the cluster-size will be 4096 after making a filesystem because in ext2fs_initialize() set_field() needs to check 'param->s_log_cluster_size' and s_log_cluster_size is 0 as cluster-size is 1024. Then s_log_cluster_size will be assigned to s_log_block_size+4. So we never set cluster-size to 1024. Another bug is that when cluster-size is 512M EXT2FS_C2B will return 0. So s_blocks_per_group will be assigned to zero and we will meet a 'division by zero' error. Here we reduce the range of cluster-size and check s_blocks_per_group=0 to avoid 'division by zero' error. Signed-off-by: Zheng Liu <wenqing.lz@xxxxxxxxxx> --- lib/ext2fs/initialize.c | 4 ++++ misc/mke2fs.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index dca0d9a..0eccd59 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -226,6 +226,10 @@ errcode_t ext2fs_initialize(const char *name, int flags, super->s_clusters_per_group = EXT2_MAX_CLUSTERS_PER_GROUP(super); super->s_blocks_per_group = EXT2FS_C2B(fs, super->s_clusters_per_group); + if (super->s_blocks_per_group == 0) { + retval = EXT2_ET_TOOSMALL; + goto cleanup; + } } else { set_field(s_blocks_per_group, fs->blocksize * 8); if (super->s_blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(super)) diff --git a/misc/mke2fs.c b/misc/mke2fs.c index bf4d7a2..f4140a1 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -1384,8 +1384,8 @@ profile_error: break; case 'C': cluster_size = strtoul(optarg, &tmp, 0); - if (cluster_size < EXT2_MIN_CLUSTER_SIZE || - cluster_size > EXT2_MAX_CLUSTER_SIZE || *tmp) { + if (cluster_size <= EXT2_MIN_CLUSTER_SIZE || + cluster_size >= EXT2_MAX_CLUSTER_SIZE || *tmp) { com_err(program_name, 0, _("invalid cluster size - %s"), optarg); -- 1.7.12.rc2.18.g61b472e -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html