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

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