* grub-core/fs/btrfs.c (grub_btrfs_device): New field size.

(read_sblock): Don't attempt to read superblocks outside the disk size.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-01-25 15:10:56 +01:00
parent ff4479581d
commit e06c2e7abc
2 changed files with 11 additions and 1 deletions

View file

@ -1,3 +1,8 @@
2012-01-25 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/fs/btrfs.c (grub_btrfs_device): New field size.
(read_sblock): Don't attempt to read superblocks outside the disk size.
2012-01-25 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/fs/nilfs2.c (grub_nilfs2_load_sb): Use device size from

View file

@ -49,7 +49,8 @@ typedef grub_uint16_t grub_btrfs_uuid_t[8];
struct grub_btrfs_device
{
grub_uint64_t device_id;
grub_uint8_t dummy[0x62 - 8];
grub_uint64_t size;
grub_uint8_t dummy[0x62 - 0x10];
} __attribute__ ((packed));
struct grub_btrfs_superblock
@ -248,6 +249,10 @@ read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb)
for (i = 0; i < ARRAY_SIZE (superblock_sectors); i++)
{
struct grub_btrfs_superblock sblock;
/* Don't try additional superblocks beyond device size. */
if (i && (grub_le_to_cpu64 (sblock.this_device.size)
>> GRUB_DISK_SECTOR_BITS) <= superblock_sectors[i])
break;
err = grub_disk_read (disk, superblock_sectors[i], 0,
sizeof (sblock), &sblock);
if (err == GRUB_ERR_OUT_OF_RANGE)