]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
filefrag: fix segfault on virtual fs
authorEric Sandeen <sandeen@redhat.com>
Sat, 28 Jul 2012 21:52:13 +0000 (17:52 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 28 Jul 2012 21:53:30 +0000 (17:53 -0400)
filefrag on a virtual fs like proc segfaults:

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>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/filefrag.c

index af008fbcf026ccbc999969f5b4b54ced9ddc7497..3ec788feae73fd72bddcd67e4791311176694612 100644 (file)
@@ -360,11 +360,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;