Author: ae
Date: Mon Sep  1 07:34:36 2014
New Revision: 270918
URL: http://svnweb.freebsd.org/changeset/base/270918

Log:
  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.

Modified:
  stable/9/sys/boot/common/part.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/boot/   (props changed)

Modified: stable/9/sys/boot/common/part.c
==============================================================================
--- stable/9/sys/boot/common/part.c     Mon Sep  1 07:34:16 2014        
(r270917)
+++ stable/9/sys/boot/common/part.c     Mon Sep  1 07:34:36 2014        
(r270918)
@@ -212,8 +212,8 @@ gpt_checktbl(const struct gpt_hdr *hdr, 
                        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, voi
            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, voi
                    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, voi
                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));
_______________________________________________
svn-src-stable-9@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-stable-9
To unsubscribe, send any mail to "svn-src-stable-9-unsubscr...@freebsd.org"

Reply via email to