diff mbox

filefrag: Fix segfault on virtual fs

Message ID 4FE9C02C.8040703@redhat.com
State Accepted, archived
Headers show

Commit Message

Eric Sandeen June 26, 2012, 1:59 p.m. UTC
filefrag on a virtual fs like proc segfaults:

# filefrag /proc/filesystems 
Floating point exception

because stat.f_blocks is 0, so the calculation of cylgroups is 0,
which leads to a divide by 0 when calculating expected extents.

Since it's only used for ext2 filesystems anyway, just move
the calculation of expected under "if (is_ext2)" to fix this.

Reported-by: Max Beikirch <maxnet@onlinehome.de>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---


--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Theodore Ts'o July 28, 2012, 9:43 p.m. UTC | #1
On Tue, Jun 26, 2012 at 03:59:08AM -0000, Eric Sandeen wrote:
> filefrag on a virtual fs like proc segfaults:
> 
> # filefrag /proc/filesystems 
> Floating point exception
> 
> because stat.f_blocks is 0, so the calculation of cylgroups is 0,
> which leads to a divide by 0 when calculating expected extents.
> 
> Since it's only used for ext2 filesystems anyway, just move
> the calculation of expected under "if (is_ext2)" to fix this.
> 
> Reported-by: Max Beikirch <maxnet@onlinehome.de>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Applied, thanks.

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/misc/filefrag.c b/misc/filefrag.c
index 0583e91..b6e7d62 100644
--- a/misc/filefrag.c
+++ b/misc/filefrag.c
@@ -365,11 +366,12 @@  static void frag_report(const char *filename)
 	else
 		printf("%s: %d extents found", filename, num_extents);
 	/* count, and thus expected, only set for indirect FIBMAP'd files */
-	expected = (count/((bs*8)-(fsinfo.f_files/8/cylgroups)-3))+1;
-	if (is_ext2 && expected && expected < num_extents)
-		printf(", perfection would be %d extent%s\n", expected,
-			(expected>1) ? "s" : "");
-	else
+	if (is_ext2) {
+		expected = (count/((bs*8)-(fsinfo.f_files/8/cylgroups)-3))+1;
+		if (expected && expected < num_extents)
+			printf(", perfection would be %d extent%s\n", expected,
+				(expected>1) ? "s" : "");
+	} else
 		fputc('\n', stdout);
 	close(fd);
 	once = 0;