[Parted-commits] GNU Parted Official Repository: Changes to 'master'

Jim Meyering meyering at alioth.debian.org
Thu Sep 20 18:28:04 UTC 2012


 NEWS                                          |    7 +++
 libparted/labels/mac.c                        |   14 ++++++-
 tests/Makefile.am                             |    1 
 tests/t0203-gpt-create-on-min-sized-device.sh |    2 -
 tests/t0350-mac-PT-increases-sector-size.sh   |   49 ++++++++++++++++++++++++++
 5 files changed, 71 insertions(+), 2 deletions(-)

New commits:
commit 6499402a18baf22f08084acb289431b731d3afda
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu Sep 20 20:18:50 2012 +0200

    tests: mac: exercise the just-fixed bug
    
    * tests/t0350-mac-PT-increases-sector-size.sh: New test.
    * tests/Makefile.am (TESTS): Add it.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 66b9361..96abecb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -30,6 +30,7 @@ TESTS = \
   t0280-gpt-corrupt.sh \
   t0300-dos-on-gpt.sh \
   t0301-overwrite-gpt-pmbr.sh \
+  t0350-mac-PT-increases-sector-size.sh \
   t0400-loop-clobber-infloop.sh \
   t0500-dup-clobber.sh \
   t0501-duplicate.sh \
diff --git a/tests/t0350-mac-PT-increases-sector-size.sh b/tests/t0350-mac-PT-increases-sector-size.sh
new file mode 100644
index 0000000..2dbd8cd
--- /dev/null
+++ b/tests/t0350-mac-PT-increases-sector-size.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# With parted-3.1, a MAC partition table that specified a sector size (B)
+# larger than what the kernel told us (SS) would cause parted to read B
+# bytes into a smaller, SS-byte buffer, clobbering heap storage.
+
+# Copyright (C) 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+require_512_byte_sector_size_
+
+dev=loop-file
+ss=$sector_size_
+
+dd if=/dev/null of=$dev bs=$ss seek=2000 || framework_failure
+parted -s $dev mklabel mac > out 2>&1 || fail=1
+# expect no output
+compare /dev/null out || fail=1
+
+# Poke a big-endian 1024 into the 2-byte block_size slot.
+perl -e 'print pack("S>", 1024)'|dd of=$dev bs=1 seek=2 count=2 conv=notrunc \
+  || fail=1
+
+printf 'ignore\ncancel\n' > in || framework_failure
+
+cat <<EOF > exp
+BYT;
+FILE:2000s:file:1024:512:unknown::;
+EOF
+
+parted -m ---pretend-input-tty $dev u s p < in > err 2>&1 || fail=1
+sed 's,
   *
,,g;s!^/[^:]*:!FILE:!' err \
+  | grep -Evi '^(ignore|fix|error|warning)' \
+  > k && mv k err || fail=1
+compare exp err || fail=1
+
+Exit $fail

commit 6c7932b90a9d078ffaf8ec9482b272c67d75a01d
Author: Brian C. Lane <bcl at redhat.com>
Date:   Tue Sep 4 16:42:34 2012 -0700

    mac: don't let larger partition-table-specified block size evoke UB
    
    For example, in reading a MAC partition table on a 512-byte sector-size
    disk, _disk_analyse_block_size could find reason to ask if it's ok to
    increase that to e.g., 2048.  Upon a positive reply, we would read 2048
    bytes into a 512-byte buffer.
    
    * libparted/labels/mac.c (mac_read): If needed, reallocate "buf"
    to accommodate a new, larger sector size.
    * NEWS (Bug fixes): Mention it.

diff --git a/NEWS b/NEWS
index f929b99..bab3afb 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,13 @@ GNU parted NEWS                                    -*- outline -*-
 
 ** Bug Fixes
 
+  libparted: mac: a MAC partition table could have a block_size larger
+  than the one the kernel told us about.  Upon reading that partition
+  table, libparted would ask if it's ok to use the larger block size.
+  If you were to respond in the affirmative, libparted would read the
+  larger number of bytes into a buffer of the shorter length,
+  overrunning it.
+
   libparted: gpt: fix gpt_get_max_supported_partition_count to work
   also on little-endian systems.
 
diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
index 1f59a1a..2485187 100644
--- a/libparted/labels/mac.c
+++ b/libparted/labels/mac.c
@@ -738,13 +738,16 @@ mac_read (PedDisk* disk)
 	if (!ptt_read_sector (disk->dev, 0, &buf))
 		return 0;
 
-	MacRawDisk *raw_disk = (MacRawDisk *) buf;
+	MacRawDisk *raw_disk = buf;
 
 	if (!_check_signature (raw_disk))
 		goto error;
 
+	/* Record the original sector size;  this function may change it.  */
+	PedSector ss0 = disk->dev->sector_size;
 	if (!_disk_analyse_block_size (disk, raw_disk))
 		goto error;
+
 	if (!_disk_analyse_ghost_size (disk))
 		goto error;
 	ghost_size = mac_disk_data->ghost_size;
@@ -759,6 +762,15 @@ mac_read (PedDisk* disk)
 		mac_disk_data->block_size = raw_disk->block_size;
 	}
 
+	/* If _disk_analyse_block_size has increased the sector_size,
+	   reallocate this buffer, so we can still read a sector into it.  */
+	if (ss0 < disk->dev->sector_size) {
+		free (buf);
+		buf = ped_malloc (disk->dev->sector_size);
+		if (buf == NULL)
+			goto error;
+	}
+
 	for (num=1; num==1 || num <= last_part_entry_num; num++) {
 		void *raw_part = buf;
 		if (!ped_device_read (disk->dev, raw_part,

commit bcc6517853c09f979951ab483bd6560d45bf8e3f
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu Sep 20 20:22:13 2012 +0200

    tests: avoid syntax-check failure for reversed compare args
    
    * tests/t0203-gpt-create-on-min-sized-device.sh: Reverse args,
    so that any diff output (upon failed test) looks sensible.

diff --git a/tests/t0203-gpt-create-on-min-sized-device.sh b/tests/t0203-gpt-create-on-min-sized-device.sh
index 113e191..4cec64c 100644
--- a/tests/t0203-gpt-create-on-min-sized-device.sh
+++ b/tests/t0203-gpt-create-on-min-sized-device.sh
@@ -42,6 +42,6 @@ echo Error: device is so small it cannot even accommodate GPT headers \
 # Try to create a GPT partition table in too little space.  This must fail.
 parted -s $dev mklabel gpt > out 2>&1 && fail=1
 # There must be a diagnostic.
-compare out exp || fail=1
+compare exp out || fail=1
 
 Exit $fail



More information about the Parted-commits mailing list