OSDN Git Service

btrfs: Add an assertion to warn incorrect case in insert_inline_extent()
authorJia-Ju Bai <baijiaju1990@gmail.com>
Sat, 27 Jul 2019 08:51:13 +0000 (16:51 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 9 Sep 2019 12:59:00 +0000 (14:59 +0200)
In insert_inline_extent(), the case that checks compressed_size > 0
and compressed_pages = NULL cannot occur, otherwise a null-pointer
dereference may occur on line 215:

     cpage = compressed_pages[i];

To catch this incorrect case, an assertion is added.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c

index c3feb53..20963b6 100644 (file)
@@ -176,6 +176,9 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans,
        size_t cur_size = size;
        unsigned long offset;
 
+       ASSERT((compressed_size > 0 && compressed_pages) ||
+              (compressed_size == 0 && !compressed_pages));
+
        if (compressed_size && compressed_pages)
                cur_size = compressed_size;