The size of the GPT table can not be less than one sector.

Reported by:	rodrigc@
MFC after:	1 week
This commit is contained in:
Andrey V. Elsukov 2014-08-24 09:20:30 +00:00
parent abd386bafe
commit 69ce0dbce3

View File

@ -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) {