From a8ed877a78d1c1e6eb7255fd3ab2e393aa408f54 Mon Sep 17 00:00:00 2001 From: ae Date: Mon, 25 Aug 2014 07:15:14 +0000 Subject: Since the size of GPT entry may differ from the sizeof(struct gpt_ent), use the size from GPT header to iterate entries. Suggested by: marcel@ MFC after: 1 week --- sys/boot/common/part.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sys/boot/common') diff --git a/sys/boot/common/part.c b/sys/boot/common/part.c index d0ee938..086809f 100644 --- a/sys/boot/common/part.c +++ b/sys/boot/common/part.c @@ -212,8 +212,8 @@ gpt_checktbl(const struct gpt_hdr *hdr, u_char *tbl, size_t size, return (-1); } } - ent = (struct gpt_ent *)tbl; - for (i = 0; i < cnt; i++, ent++) { + for (i = 0; i < cnt; i++) { + ent = (struct gpt_ent *)(tbl + i * hdr->hdr_entsz); uuid_letoh(&ent->ent_type); if (uuid_equal(&ent->ent_type, &gpt_uuid_unused, NULL)) continue; @@ -303,10 +303,10 @@ ptable_gptread(struct ptable *table, void *dev, diskread_t dread) table->type = PTABLE_NONE; goto out; } - ent = (struct gpt_ent *)tbl; size = MIN(hdr.hdr_entries * hdr.hdr_entsz, MAXTBLSZ * table->sectorsize); - for (i = 0; i < size / hdr.hdr_entsz; i++, ent++) { + for (i = 0; i < size / hdr.hdr_entsz; i++) { + ent = (struct gpt_ent *)(tbl + i * hdr.hdr_entsz); if (uuid_equal(&ent->ent_type, &gpt_uuid_unused, NULL)) continue; entry = malloc(sizeof(*entry)); -- cgit v1.1