diff options
author | Theodore Ts'o <tytso@mit.edu> | 2017-12-12 21:46:36 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2017-12-12 21:46:36 -0500 |
commit | 53600d306dbb0eb901a04d76a4a97f45777d39c8 (patch) | |
tree | 927d100f452af8ccb836953807d7ddc2bf9848f5 | |
parent | f222de72566dbad0c7ae9abb1bcbe2d1fd55b126 (diff) | |
download | e2fsprogs-53600d306dbb0eb901a04d76a4a97f45777d39c8.tar.gz |
e2fsck: fix potential Floating Point Exception in show_stats()
If the free inodes count in the superblock is equal to the inodes
count in the superblock (which is not possible with a valid file
system and will be fixed by e2fsck unless it is prevented by, for
example, e2fsck -n), it is possible for e2fsck to crash due to a
divide by zero error.
Fix this potential bug.
Addresses-Debian-Bug: #879220
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r-- | e2fsck/unix.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/e2fsck/unix.c b/e2fsck/unix.c index b46dcb2dc..2e9be8b88 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -106,7 +106,7 @@ static void show_stats(e2fsck_t ctx) unsigned int dir_links; unsigned int num_files, num_links; __u32 *mask, m; - int frag_percent_file, frag_percent_dir, frag_percent_total; + int frag_percent_file = 0, frag_percent_dir = 0, frag_percent_total = 0; int i, j, printed = 0; dir_links = 2 * ctx->fs_directory_count - 1; @@ -119,16 +119,18 @@ static void show_stats(e2fsck_t ctx) blocks_used = (ext2fs_blocks_count(fs->super) - ext2fs_free_blocks_count(fs->super)); - frag_percent_file = (10000 * ctx->fs_fragmented) / inodes_used; - frag_percent_file = (frag_percent_file + 5) / 10; + if (inodes_used > 0) { + frag_percent_file = (10000 * ctx->fs_fragmented) / inodes_used; + frag_percent_file = (frag_percent_file + 5) / 10; - frag_percent_dir = (10000 * ctx->fs_fragmented_dir) / inodes_used; - frag_percent_dir = (frag_percent_dir + 5) / 10; + frag_percent_dir = (10000 * ctx->fs_fragmented_dir) / inodes_used; + frag_percent_dir = (frag_percent_dir + 5) / 10; - frag_percent_total = ((10000 * (ctx->fs_fragmented + - ctx->fs_fragmented_dir)) - / inodes_used); - frag_percent_total = (frag_percent_total + 5) / 10; + frag_percent_total = ((10000 * (ctx->fs_fragmented + + ctx->fs_fragmented_dir)) + / inodes_used); + frag_percent_total = (frag_percent_total + 5) / 10; + } if (!verbose) { log_out(ctx, _("%s: %u/%u files (%0d.%d%% non-contiguous), " |