]> git.hungrycats.org Git - btrfs-progs/commitdiff
btrfs-progs: image: avoid NULL-ptr-deref in build_chunk_tree()
authorQu Wenruo <wqu@suse.com>
Sun, 25 Oct 2026 08:41:40 +0000 (19:11 +1030)
committerQu Wenruo <wqu@suse.com>
Mon, 26 Oct 2026 21:38:10 +0000 (08:08 +1030)
Although very unlikely, if there is a header that has no item in it,
build_chunk_tree() left @item as NULL, then later during the error
message we still call "get_unaligned_le64(&item->bytenr)", which is
going to trigger a NULL-pointer dereference.

Fix it by removing the get_unaligned_le64() call.

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
image/image-restore.c

index b1de96c51efa22bbdee1ae34fdfeab7e767127c2..89ce2f3e79ede6a8925d20275d21d260f129a639 100644 (file)
@@ -1140,7 +1140,7 @@ static int build_chunk_tree(struct mdrestore_struct *mdres,
        }
 
        if (!item || get_unaligned_le64(&item->bytenr) != BTRFS_SUPER_INFO_OFFSET) {
-               error("did not find superblock at %llu", get_unaligned_le64(&item->bytenr));
+               error("did not find superblock");
                return -EINVAL;
        }