From owner-svn-src-stable-9@FreeBSD.ORG Mon Sep 1 07:34:37 2014 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9895CBEB; Mon, 1 Sep 2014 07:34:37 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6A2BB1228; Mon, 1 Sep 2014 07:34:37 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s817Yb0D063187; Mon, 1 Sep 2014 07:34:37 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s817Ybxf063186; Mon, 1 Sep 2014 07:34:37 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201409010734.s817Ybxf063186@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Mon, 1 Sep 2014 07:34:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r270918 - stable/9/sys/boot/common X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Sep 2014 07:34:37 -0000 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));