btrfs-progs: fi du: catch bogus extent lengths
authorDavid Sterba <dsterba@suse.com>
Wed, 7 Sep 2016 12:51:17 +0000 (14:51 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 3 Oct 2016 09:33:04 +0000 (11:33 +0200)
If we get a zero-length from the ioctl for whatever reason, we should
not crash.

Signed-off-by: David Sterba <dsterba@suse.com>
cmds-fi-du.c

index ec8e550..47ceb96 100644 (file)
@@ -79,7 +79,7 @@ static int add_shared_extent(u64 start, u64 len, struct rb_root *root)
 {
        struct shared_extent *sh;
 
-       BUG_ON(len == 0);
+       ASSERT(len != 0);
 
        sh = calloc(1, sizeof(*sh));
        if (!sh)
@@ -326,6 +326,12 @@ static int du_calc_file_space(int fd, struct rb_root *shared_extents,
                        if (flags & SKIP_FLAGS)
                                continue;
 
+                       if (ext_len == 0) {
+                               warning("extent %llu has length 0, skipping",
+                                       (unsigned long long)fm_ext[i].fe_physical);
+                               continue;
+                       }
+
                        file_total += ext_len;
                        if (flags & FIEMAP_EXTENT_SHARED) {
                                file_shared += ext_len;