btrfs: do proper error handling in btrfs_insert_xattr_item
authorDavid Sterba <dsterba@suse.com>
Fri, 17 Feb 2017 18:42:43 +0000 (19:42 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 28 Feb 2017 13:27:11 +0000 (14:27 +0100)
The space check in btrfs_insert_xattr_item is duplicated in it's caller
(do_setxattr) so we won't hit the BUG_ON. Continuing without any check
could be disasterous so turn it to a proper error handling.

Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/dir-item.c

index b13d9536d4de8c523b7da16d9b782954d8746377..60a750678a82b335ab7fd0e9432288d013c52e64 100644 (file)
@@ -80,7 +80,8 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
        struct extent_buffer *leaf;
        u32 data_size;
 
-       BUG_ON(name_len + data_len > BTRFS_MAX_XATTR_SIZE(root->fs_info));
+       if (name_len + data_len > BTRFS_MAX_XATTR_SIZE(root->fs_info))
+               return -ENOSPC;
 
        key.objectid = objectid;
        key.type = BTRFS_XATTR_ITEM_KEY;