From owner-svn-src-head@FreeBSD.ORG Fri Sep 12 03:54:16 2014 Return-Path: Delivered-To: svn-src-head@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 D7C9ABE9; Fri, 12 Sep 2014 03:54:16 +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 A8F8798; Fri, 12 Sep 2014 03:54:16 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8C3sGBJ050612; Fri, 12 Sep 2014 03:54:16 GMT (envelope-from marcel@FreeBSD.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8C3sG5S050611; Fri, 12 Sep 2014 03:54:16 GMT (envelope-from marcel@FreeBSD.org) Message-Id: <201409120354.s8C3sG5S050611@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: marcel set sender to marcel@FreeBSD.org using -f From: Marcel Moolenaar Date: Fri, 12 Sep 2014 03:54:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r271448 - head/usr.bin/mkimg X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Sep 2014 03:54:17 -0000 Author: marcel Date: Fri Sep 12 03:54:16 2014 New Revision: 271448 URL: http://svnweb.freebsd.org/changeset/base/271448 Log: Fix checksum calculation: 1. Iterate over all partitions counted in the label, which can be more than the number of partitions given to mkimg(1). 2. Start the checksum from the beginning of the label; not the beginning of the bootarea. Tested with bsdlabel(8). MFC after: 3 days Modified: head/usr.bin/mkimg/bsd.c Modified: head/usr.bin/mkimg/bsd.c ============================================================================== --- head/usr.bin/mkimg/bsd.c Fri Sep 12 02:38:10 2014 (r271447) +++ head/usr.bin/mkimg/bsd.c Fri Sep 12 03:54:16 2014 (r271448) @@ -68,7 +68,7 @@ bsd_write(lba_t imgsz, void *bootcode) struct disklabel *d; struct partition *dp; struct part *part; - int error, n; + int bsdparts, error, n; uint16_t checksum; buf = malloc(BBSIZE); @@ -80,6 +80,9 @@ bsd_write(lba_t imgsz, void *bootcode) } else memset(buf, 0, BBSIZE); + bsdparts = nparts + 1; /* Account for c partition */ + if (bsdparts < MAXPARTITIONS) + bsdparts = MAXPARTITIONS; imgsz = (lba_t)ncyls * nheads * nsecs; error = image_set_size(imgsz); if (error) { @@ -97,7 +100,7 @@ bsd_write(lba_t imgsz, void *bootcode) le32enc(&d->d_secperunit, imgsz); le16enc(&d->d_rpm, 3600); le32enc(&d->d_magic2, DISKMAGIC); - le16enc(&d->d_npartitions, (8 > nparts + 1) ? 8 : nparts + 1); + le16enc(&d->d_npartitions, bsdparts); le32enc(&d->d_bbsize, BBSIZE); dp = &d->d_partitions[RAW_PART]; @@ -110,9 +113,9 @@ bsd_write(lba_t imgsz, void *bootcode) dp->p_fstype = ALIAS_TYPE2INT(part->type); } - dp = &d->d_partitions[nparts + 1]; + dp = &d->d_partitions[bsdparts]; checksum = 0; - for (p = buf; p < (u_char *)dp; p += 2) + for (p = (void *)d; p < (u_char *)dp; p += 2) checksum ^= le16dec(p); le16enc(&d->d_checksum, checksum);