From: Theodore Ts'o Date: Wed, 13 Dec 2017 02:46:36 +0000 (-0500) Subject: e2fsck: fix potential Floating Point Exception in show_stats() X-Git-Tag: v1.43.8~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53600d306dbb0eb901a04d76a4a97f45777d39c8;p=thirdparty%2Fe2fsprogs.git 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 --- 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), "