[PATCH 5/8] gpt_probe: don't attempt to read beyond end of a very small disk
Jim Meyering
meyering at redhat.com
Fri Nov 13 12:40:29 UTC 2009
* libparted/labels/gpt.c (gpt_probe): Don't try to read the
2nd sector if that's beyond the end of the disk.
* tests/t0001-tiny.sh: New test, to expose the above boundary-case bug.
Part of the msdos-partition-creation process involves probing for
other types of partition tables. Probing for gpt would evoke a
nonsensical diagnostic.
* tests/Makefile.am (TESTS): Add t0001-tiny.sh.
---
libparted/labels/gpt.c | 3 ++
tests/Makefile.am | 1 +
tests/t0001-tiny.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+), 0 deletions(-)
create mode 100755 tests/t0001-tiny.sh
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 5037d9b..aca555a 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -444,6 +444,9 @@ gpt_probe (const PedDevice *dev)
PED_ASSERT (dev != NULL, return 0);
+ if (dev->length <= 1)
+ return 0;
+
if (ped_device_read (dev, pth_raw, 1, GPT_HEADER_SECTORS)
|| ped_device_read (dev, pth_raw, dev->length - 1, GPT_HEADER_SECTORS))
{
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 79c01b3..ece3f64 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,6 @@
TESTS = \
t0000-basic.sh \
+ t0001-tiny.sh \
t0010-script-no-ctrl-chars.sh \
t0100-print.sh \
t0200-gpt.sh \
diff --git a/tests/t0001-tiny.sh b/tests/t0001-tiny.sh
new file mode 100755
index 0000000..373a68d
--- /dev/null
+++ b/tests/t0001-tiny.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+# operate on a very small (1-sector) "disk"
+
+# Copyright (C) 2009 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/>.
+
+if test "$VERBOSE" = yes; then
+ set -x
+ parted --version
+fi
+
+: ${srcdir=.}
+. $srcdir/t-lib.sh
+
+ss=$sector_size_
+dev=loop-file
+
+fail=0
+
+for opt in '' -s; do
+
+ dd if=/dev/null of=$dev bs=1 seek=$ss || framework_failure
+
+ # create an msdos partition table:
+ # Before parted-2.1, without -s, this would fail with a bogus diagnostic:
+ # Error: Success during read on .../tests/loop-file
+ # Retry/Ignore/Cancel? ^C
+ parted $opt $dev mklabel msdos ---pretend-input-tty </dev/null > out 2>&1 \
+ || fail=1
+ # expect no output
+ sed 's/.*WARNING: You are not superuser.*//;/^$/d' out > k && mv k out || fail=1
+ compare out /dev/null || fail=1
+
+ parted -s $dev p || fail=1
+ rm -f $dev
+
+done
+
+Exit $fail
--
1.6.5.2.372.gc0502
More information about the parted-devel
mailing list