[parted-devel] [PATCH 3/8] libparted: (nilfs2) do not fail with tiny partition

Jim Meyering jim at meyering.net
Wed Sep 28 19:31:51 UTC 2011


Petr Uzel wrote:
> nilfs2_probe used to fail with the partition which is 1 sector long,
> since NILFS_SB2_OFFSET(x) returns negative number for x < 8. This
> led to crash in ped_geometry_read_alloc().
>
> * libparted/fs/nilfs2/nilfs2.c (nilfs2_probe): Make sure sb2off is
> not negative.
>
> Signed-off-by: Petr Uzel <petr.uzel at suse.cz>
> ---
>  libparted/fs/nilfs2/nilfs2.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/libparted/fs/nilfs2/nilfs2.c b/libparted/fs/nilfs2/nilfs2.c
> index 511b155..6a97443 100644
> --- a/libparted/fs/nilfs2/nilfs2.c
> +++ b/libparted/fs/nilfs2/nilfs2.c
> @@ -115,6 +115,8 @@ nilfs2_probe (PedGeometry* geom)
>  		return NULL;
>
>  	sb2off = NILFS_SB2_OFFSET(length);
> +	if (sb2off < 0)
> +		sb2off = 0;
>
>  	if (ped_geometry_read_alloc(geom, &sb_v, 2, 1))
>  		sb = sb_v;

Hi Petr,

Thanks for all of those patches.

I posted a patch for the above some time ago,

    Re: parted crash accessing GPT table -
    http://lists.gnu.org/archive/html/bug-parted/2011-06/msg00043.html
    [note the NEWS entry and attribution]

but for lack of a test case did not push it.
Today I wrote a test to exercise it.
In the process, I realized that the new test was not quite
strong enough.  We don't want to allow an offset that is equal
to 0, or to 1 or 2.  Probably not 3 either, but I've gone ahead
and allowed 3.  Later tests will catch that.

I'm about to push these two and will review your others tomorrow.

>From 2147402b83b27a35011cad032d0519c4a0672280 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Sat, 25 Jun 2011 08:49:58 +0200
Subject: [PATCH 1/2] libparted: fix a bug in the nilfs2 probe function

* libparted/fs/nilfs2/nilfs2.c (nilfs2_probe): Reject this partition
if we get a negative sb2 offset.  Passing a negative offset to
ped_geometry_read_alloc would evoke a failed assertion.
Bug introduced by 2010-07-09 commit d463e7de.
* NEWS: (Bug fixes): Mention it.
Reported by Daniel Fandrich in
http://thread.gmane.org/gmane.comp.gnu.parted.bugs/10466/focus=10472
---
 NEWS                         |    3 +++
 libparted/fs/nilfs2/nilfs2.c |    5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index cb61ac1..e2258ca 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ GNU parted NEWS                                    -*- outline -*-

 ** Bug fixes

+  libparted: no longer aborts (failed assertion) due to a nilfs2_probe bug
+  [bug introduced in parted-2.4 with the addition of nilfs2 support]
+
   libparted: no longer aborts when reading a truncated GPT-formatted device

   libparted: works with a two-component linux kernel version number like 3.0
diff --git a/libparted/fs/nilfs2/nilfs2.c b/libparted/fs/nilfs2/nilfs2.c
index 511b155..166c54c 100644
--- a/libparted/fs/nilfs2/nilfs2.c
+++ b/libparted/fs/nilfs2/nilfs2.c
@@ -108,13 +108,14 @@ nilfs2_probe (PedGeometry* geom)
 	struct nilfs2_super_block *sb = NULL;
 	struct nilfs2_super_block *sb2 = NULL;
 	PedSector length = geom->length;
-	PedSector sb2off;

 	/* ignore if sector size is not 512bytes for now  */
 	if (geom->dev->sector_size != PED_SECTOR_SIZE_DEFAULT)
 		return NULL;

-	sb2off = NILFS_SB2_OFFSET(length);
+	PedSector sb2off = NILFS_SB2_OFFSET(length);
+	if (sb2off <= 2)
+		return NULL;

 	if (ped_geometry_read_alloc(geom, &sb_v, 2, 1))
 		sb = sb_v;
--
1.7.7.rc0.362.g5a14


>From 196364e9c02ef349632a682a852ce114ed31c869 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Wed, 28 Sep 2011 19:43:40 +0200
Subject: [PATCH 2/2] tests: test for the nilfs2 bug

* tests/t4300-nilfs2-tiny.sh: New test.
* tests/Makefile.am (TESTS): Add it.
---
 tests/Makefile.am          |    1 +
 tests/t4300-nilfs2-tiny.sh |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)
 create mode 100755 tests/t4300-nilfs2-tiny.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 86402c0..e721f88 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -38,6 +38,7 @@ TESTS = \
   t4100-dvh-partition-limits.sh \
   t4100-msdos-starting-sector.sh \
   t4200-partprobe.sh \
+  t4300-nilfs2-tiny.sh \
   t5000-tags.sh \
   t6000-dm.sh \
   t7000-scripting.sh \
diff --git a/tests/t4300-nilfs2-tiny.sh b/tests/t4300-nilfs2-tiny.sh
new file mode 100755
index 0000000..009a3cd
--- /dev/null
+++ b/tests/t4300-nilfs2-tiny.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Trigger a nilfs2-related bug.
+
+# Copyright (C) 2011 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
+ss=$sector_size_
+
+n_sectors=200
+dev=dev-file
+dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || framework_failure_
+
+# Create a tiny, 7-sector partition.
+parted -s $dev mklabel gpt mkpart p1 64s 70s || framework_failure_
+
+# This used to make parted abort.
+parted -s $dev u s p || fail=1
+
+Exit $fail
--
1.7.7.rc0.362.g5a14



More information about the parted-devel mailing list