summaryrefslogtreecommitdiff
path: root/misc/mke2fs.c
diff options
context:
space:
mode:
authorEric Sandeen <esandeen@redhat.com>2006-09-12 14:56:17 -0400
committerTheodore Ts'o <tytso@mit.edu>2006-09-12 14:56:17 -0400
commitf335864338a6fbce8134a445ffdd0cdeb3f3f1bc (patch)
treeb148781b1a0fb699fe051c1da952257a5851fc6a /misc/mke2fs.c
parentabf23439d51a3ddbca475b931abebd381ff7ceea (diff)
downloade2fsprogs-f335864338a6fbce8134a445ffdd0cdeb3f3f1bc.tar.gz
Add checks to make sure inode counts don't overflow a 32-bit value
Signed-off-by: Eric Sandeen <esandeen@redhat.com>
Diffstat (limited to 'misc/mke2fs.c')
-rw-r--r--misc/mke2fs.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 05ee9d8d..256c8133 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -896,7 +896,7 @@ static void PRS(int argc, char *argv[])
double reserved_ratio = 5.0;
int sector_size = 0;
int show_version_only = 0;
- ext2_ino_t num_inodes = 0;
+ __u64 num_inodes = 0; /* u64 to catch too-large input */
errcode_t retval;
char * oldpath = getenv("PATH");
char * extended_opts = 0;
@@ -1437,6 +1437,21 @@ static void PRS(int argc, char *argv[])
fs_param.s_inode_size = inode_size;
}
+ /* Make sure number of inodes specified will fit in 32 bits */
+ if (num_inodes == 0) {
+ __u64 n;
+ n = (__u64) fs_param.s_blocks_count * blocksize / inode_ratio;
+ if (n > ~0U) {
+ com_err(program_name, 0,
+ _("too many inodes (%llu), raise inode ratio?"), n);
+ exit(1);
+ }
+ } else if (num_inodes > ~0U) {
+ com_err(program_name, 0,
+ _("too many inodes (%llu), specify < 2^32 inodes"),
+ (__u64)num_inodes);
+ exit(1);
+ }
/*
* Calculate number of inodes based on the inode ratio
*/