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

Jim Meyering meyering at alioth.debian.org
Mon Jan 23 21:36:48 UTC 2012


 NEWS                               |    3 +
 parted/parted.c                    |    1 
 tests/Makefile.am                  |    1 
 tests/t0212-gpt-many-partitions.sh |   56 +++++++++++++++++++++++++++++++++++++
 tests/t9040-many-partitions.sh     |   38 ++++++++++++++-----------
 5 files changed, 82 insertions(+), 17 deletions(-)

New commits:
commit cd280c622f5f5f8708ace2f04118d80d9a2c6a8f
Author: Jim Meyering <meyering at redhat.com>
Date:   Mon Jan 23 21:32:00 2012 +0100

    tests: create 128 partitions also in the scsi-backed test
    
    * tests/t9040-many-partitions.sh: Tighten up: use less memory:
    1 sector per partition rather than 256.
    Exec parted just once, not once per partition.
    With that, we can increase the number of partitions to create
    from 60 (which used to take 2.5 minutes on an F12-era kernel)
    to the standard-GPT-header-imposed maximum of 128.
    Suggested by Phillip Susi.

diff --git a/tests/t9040-many-partitions.sh b/tests/t9040-many-partitions.sh
index c77628c..db065f4 100644
--- a/tests/t9040-many-partitions.sh
+++ b/tests/t9040-many-partitions.sh
@@ -25,9 +25,9 @@ grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
   skip_ 'this system lacks a new-enough libblkid'
 
 ss=$sector_size_
-partition_sectors=256  # sectors per partition
-n_partitions=60        # how many partitions to create
-start=2048             # start sector for the first partition
+partition_sectors=1    # sectors per partition
+n_partitions=128       # how many partitions to create
+start=34               # start sector for the first partition
 gpt_slop=34            # sectors at end of disk reserved for GPT
 
 n_sectors=$(($start + n_partitions * partition_sectors + gpt_slop))
@@ -43,29 +43,35 @@ n=$((n_MiB * sectors_per_MiB))
 printf "BYT;\n$scsi_dev:${n}s:scsi:$ss:$ss:gpt:Linux scsi_debug;\n" \
   > exp || fail=1
 
-parted -s $scsi_dev mklabel gpt || fail=1
-parted -s $scsi_dev u s p || fail=1
-
+cmd=
 i=1
-t0=$(date +%s.%N)
 while :; do
-    end=$((start + partition_sectors - 1))
-    parted -s $scsi_dev mkpart p$i ${start}s ${end}s || fail=1
-    printf "$i:${start}s:${end}s:${partition_sectors}s::p$i:;\n" >> exp
-    test $i = $n_partitions && break
-    start=$((start + partition_sectors))
-    i=$((i+1))
+    s=$((start + i - 1))
+    e=$((s + partition_sectors - 1))
+    cmd="$cmd mkpart p$i ${s}s ${e}s"
+    test $i = $n_partitions && break; i=$((i+1))
 done
+
+# Time the actual command:
+t0=$(date +%s.%N)
+parted -m -a min -s $scsi_dev mklabel gpt $cmd u s p > out 2>&1 || fail=1
 t_final=$(date +%s.%N)
 
+i=1
+while :; do
+    s=$((start + i - 1))
+    e=$((s + partition_sectors - 1))
+    printf "$i:${s}s:${e}s:${partition_sectors}s::p$i:;\n" >> exp
+    test $i = $n_partitions && break; i=$((i+1))
+done
+
 # Fail the test if it takes too long.
-# On Fedora 13, it takes about 15 seconds.
-# With older kernels, it typically takes more than 150 seconds.
+# On Fedora 16, this takes about 10 seconds for me.
+# With Fedora-12-era kernels, it typically took more than 150 seconds.
 $AWK "BEGIN {d = $t_final - $t0; n = $n_partitions; st = 60 < d;"\
 ' printf "created %d partitions in %.2f seconds\n", n, d; exit st }' /dev/null \
     || fail=1
 
-parted -m -s $scsi_dev u s p > out || fail=1
 compare exp out || fail=1
 
 Exit $fail

commit fd9fe8fa65019e62c80f87b68aa1dda46b63ecf8
Author: Jim Meyering <meyering at redhat.com>
Date:   Mon Jan 23 20:01:30 2012 +0100

    tests: exercise today's bug fix, creating a GPT table with 128 entries
    
    * tests/t0212-gpt-many-partitions.sh: New test.
    * tests/Makefile.am (TESTS): Add it.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 88efbdd..17486e2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -22,6 +22,7 @@ TESTS = \
   t0208-mkpart-end-in-IEC.sh \
   t0210-gpt-resized-partition-entry-array.sh \
   t0211-gpt-rewrite-header.sh \
+  t0212-gpt-many-partitions.sh \
   t0220-gpt-msftres.sh \
   t0250-gpt.sh \
   t0280-gpt-corrupt.sh \
diff --git a/tests/t0212-gpt-many-partitions.sh b/tests/t0212-gpt-many-partitions.sh
new file mode 100644
index 0000000..d0fc72e
--- /dev/null
+++ b/tests/t0212-gpt-many-partitions.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# gpt: create many partitions
+# Before parted-3.1, this would provoke an invalid free.
+
+# 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 $srcdir
+
+ss=$sector_size_
+
+ns=300
+n_partitions=128
+dev=dev-file
+start_sector=34
+
+# create a file large enough to hold a GPT partition table
+dd if=/dev/null of=$dev bs=$ss seek=$ns || framework_failure
+
+cmd=
+i=1
+while :; do
+  s=$((start_sector + i - 1))
+  cmd="$cmd mkpart p$i ${s}s ${s}s"
+  test $i = $n_partitions && break; i=$((i+1))
+done
+parted -m -a min -s $dev mklabel gpt $cmd u s p > out 2>&1 || fail=1
+
+nl='
+'
+exp=$(printf '%s\n' 'BYT;' "...:${ns}s:file:$ss:$ss:gpt:;")"$nl"
+
+i=1
+while :; do
+  s=$((start_sector + i - 1))
+  exp="$exp$i:${s}s:${s}s:1s::p$i:;$nl"
+  test $i = $n_partitions && break; i=$((i+1))
+done
+printf %s "$exp" > exp || fail=1
+
+sed '2s/^[^:]*:/...:/' out > k && mv k out
+compare exp out || fail=1
+
+Exit $fail

commit 4b61aedfb63cc97b405649f7261feb54cfdcdbfa
Author: Jim Meyering <meyering at redhat.com>
Date:   Mon Jan 23 19:55:39 2012 +0100

    libparted: gpt: avoid invalid free with many (~100) partitions
    
    * parted/parted.c (do_print): Remove invalid free.
    Bug introduced via v1.8.8.1-19-gb56d69c.
    * NEWS (Bug fixes): Mention this.

diff --git a/NEWS b/NEWS
index 9d189dc..484034b 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,9 @@ GNU parted NEWS                                    -*- outline -*-
 
 ** Bug fixes
 
+  libparted: avoid an invalid free when creating many partitions in
+  a GPT partition table.  [bug introduced in parted-1.9.0]
+
   The msdos partition table claimed a maximum partition count of 16
   but would allow you to go beyond that.  This resulted in the kernel
   not being informed of those partitions.  Corrected to enforce the
diff --git a/parted/parted.c b/parted/parted.c
index 96f9c34..02c5fdb 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1171,7 +1171,6 @@ do_print (PedDevice** dev)
                     //PED_ASSERT (row.cols == caption.cols)
                     table_add_row_from_strlist (table, row);
                     str_list_destroy (row);
-                    free (tmp);
                     free (start);
                     free (end);
                     free (size);



More information about the Parted-commits mailing list