gpt: fix partition table indexing and validation

Portions of the code attempted to handle the fact that GPT entries on
disk may be larger than the currently defined struct while others
assumed the data could be indexed by the struct size directly. This
never came up because no utility uses a size larger than 128 bytes but
for the sake of safety we need to do this by the spec.
This commit is contained in:
Michael Marineau 2016-08-24 16:14:20 -07:00
parent 87dfbf34c4
commit bf127238ee
4 changed files with 176 additions and 12 deletions

View file

@ -78,7 +78,7 @@ grub_find_next (const char *disk_name,
const grub_gpt_part_type_t *part_type,
char **part_name, char **part_guid)
{
struct grub_gpt_partentry *part_found = NULL;
struct grub_gpt_partentry *part, *part_found = NULL;
grub_device_t dev = NULL;
grub_gpt_t gpt = NULL;
grub_uint32_t i, part_index;
@ -95,10 +95,8 @@ grub_find_next (const char *disk_name,
if (grub_gpt_repair (dev->disk, gpt))
goto done;
for (i = 0; i < grub_le_to_cpu32 (gpt->primary.maxpart); i++)
for (i = 0; (part = grub_gpt_get_partentry (gpt, i)) != NULL; i++)
{
struct grub_gpt_partentry *part = &gpt->entries[i];
if (grub_memcmp (part_type, &part->type, sizeof (*part_type)) == 0)
{
unsigned int priority, tries_left, successful, old_priority = 0;