summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorae <ae@FreeBSD.org>2014-09-01 07:34:16 +0000
committerae <ae@FreeBSD.org>2014-09-01 07:34:16 +0000
commitbf7011b0f4aca34eadfd627e7bbc511734d3a5f4 (patch)
treebd75e1bea53fea5977e6bfdd81e92ce2d7539e01
parent68a94ff2b98bfc195e61db7053c5eaf101efae97 (diff)
downloadFreeBSD-src-bf7011b0f4aca34eadfd627e7bbc511734d3a5f4.zip
FreeBSD-src-bf7011b0f4aca34eadfd627e7bbc511734d3a5f4.tar.gz
MFC r270445:
The size of the GPT table can not be less than one sector. MFC r270521: Since the size of GPT entry may differ from the sizeof(struct gpt_ent), use the size from GPT header to iterate entries.
-rw-r--r--sys/boot/common/part.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/sys/boot/common/part.c b/sys/boot/common/part.c
index 55153aa..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;
@@ -254,8 +254,8 @@ ptable_gptread(struct ptable *table, void *dev, diskread_t dread)
table->sectorsize);
if (phdr != NULL) {
/* Read the primary GPT table. */
- size = MIN(MAXTBLSZ,
- phdr->hdr_entries * phdr->hdr_entsz / table->sectorsize);
+ size = MIN(MAXTBLSZ, (phdr->hdr_entries * phdr->hdr_entsz +
+ table->sectorsize - 1) / table->sectorsize);
if (dread(dev, tbl, size, phdr->hdr_lba_table) == 0 &&
gpt_checktbl(phdr, tbl, size * table->sectorsize,
table->sectors - 1) == 0) {
@@ -287,8 +287,9 @@ ptable_gptread(struct ptable *table, void *dev, diskread_t dread)
hdr.hdr_entsz != phdr->hdr_entsz ||
hdr.hdr_crc_table != phdr->hdr_crc_table) {
/* Read the backup GPT table. */
- size = MIN(MAXTBLSZ, phdr->hdr_entries *
- phdr->hdr_entsz / table->sectorsize);
+ size = MIN(MAXTBLSZ, (phdr->hdr_entries *
+ phdr->hdr_entsz + table->sectorsize - 1) /
+ table->sectorsize);
if (dread(dev, tbl, size, phdr->hdr_lba_table) == 0 &&
gpt_checktbl(phdr, tbl, size * table->sectorsize,
table->sectors - 1) == 0) {
@@ -302,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));
OpenPOWER on IntegriCloud