Blame SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-potential-Floating-Point-Exception-in-sho.patch

0ef434
From 63eafe15eb224f1130d7e359db088fd620187ba6 Mon Sep 17 00:00:00 2001
0ef434
From: Theodore Ts'o <tytso@mit.edu>
0ef434
Date: Tue, 12 Dec 2017 21:46:36 -0500
0ef434
Subject: [PATCH 11/16] e2fsck: fix potential Floating Point Exception in
0ef434
 show_stats()
0ef434
0ef434
commit 53600d306dbb0eb901a04d76a4a97f45777d39c8
0ef434
0ef434
If the free inodes count in the superblock is equal to the inodes
0ef434
count in the superblock (which is not possible with a valid file
0ef434
system and will be fixed by e2fsck unless it is prevented by, for
0ef434
example, e2fsck -n), it is possible for e2fsck to crash due to a
0ef434
divide by zero error.
0ef434
0ef434
Fix this potential bug.
0ef434
0ef434
Addresses-Debian-Bug: #879220
0ef434
0ef434
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
0ef434
---
0ef434
 e2fsck/unix.c | 20 +++++++++++---------
0ef434
 1 file changed, 11 insertions(+), 9 deletions(-)
0ef434
0ef434
diff --git a/e2fsck/unix.c b/e2fsck/unix.c
0ef434
index a434f1e6..84b9a454 100644
0ef434
--- a/e2fsck/unix.c
0ef434
+++ b/e2fsck/unix.c
0ef434
@@ -103,7 +103,7 @@ static void show_stats(e2fsck_t	ctx)
0ef434
 	unsigned int dir_links;
0ef434
 	unsigned int num_files, num_links;
0ef434
 	__u32 *mask, m;
0ef434
-	int frag_percent_file, frag_percent_dir, frag_percent_total;
0ef434
+	int frag_percent_file = 0, frag_percent_dir = 0, frag_percent_total = 0;
0ef434
 	int i, j, printed = 0;
0ef434
 
0ef434
 	dir_links = 2 * ctx->fs_directory_count - 1;
0ef434
@@ -116,16 +116,18 @@ static void show_stats(e2fsck_t	ctx)
0ef434
 	blocks_used = (ext2fs_blocks_count(fs->super) -
0ef434
 		       ext2fs_free_blocks_count(fs->super));
0ef434
 
0ef434
-	frag_percent_file = (10000 * ctx->fs_fragmented) / inodes_used;
0ef434
-	frag_percent_file = (frag_percent_file + 5) / 10;
0ef434
+	if (inodes_used > 0) {
0ef434
+		frag_percent_file = (10000 * ctx->fs_fragmented) / inodes_used;
0ef434
+		frag_percent_file = (frag_percent_file + 5) / 10;
0ef434
 
0ef434
-	frag_percent_dir = (10000 * ctx->fs_fragmented_dir) / inodes_used;
0ef434
-	frag_percent_dir = (frag_percent_dir + 5) / 10;
0ef434
+		frag_percent_dir = (10000 * ctx->fs_fragmented_dir) / inodes_used;
0ef434
+		frag_percent_dir = (frag_percent_dir + 5) / 10;
0ef434
 
0ef434
-	frag_percent_total = ((10000 * (ctx->fs_fragmented +
0ef434
-					ctx->fs_fragmented_dir))
0ef434
-			      / inodes_used);
0ef434
-	frag_percent_total = (frag_percent_total + 5) / 10;
0ef434
+		frag_percent_total = ((10000 * (ctx->fs_fragmented +
0ef434
+						ctx->fs_fragmented_dir))
0ef434
+				      / inodes_used);
0ef434
+		frag_percent_total = (frag_percent_total + 5) / 10;
0ef434
+	}
0ef434
 
0ef434
 	if (!verbose) {
0ef434
 		log_out(ctx, _("%s: %u/%u files (%0d.%d%% non-contiguous), "
0ef434
-- 
0ef434
2.20.1
0ef434