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

Jim Meyering meyering at alioth.debian.org
Wed Mar 16 18:47:32 UTC 2011


 NEWS                            |    5 +++++
 libparted/fs/nilfs2/Makefile.am |    2 ++
 libparted/fs/nilfs2/nilfs2.c    |   26 --------------------------
 libparted/labels/gpt.c          |   18 +++++++++++++++---
 parted/Makefile.am              |    3 ---
 parted/parted.c                 |    4 ++--
 6 files changed, 24 insertions(+), 34 deletions(-)

New commits:
commit 163150a9e5a1c62a67dda1861e139b77584b3434
Author: Jim Meyering <meyering at redhat.com>
Date:   Fri Mar 11 08:22:13 2011 +0100

    maint: rename a variable
    
    * libparted/labels/gpt.c (_header_is_valid): Rename a variable,
    and switch to more readable range-checking logic.

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index bfbe7f9..e1c0a32 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -639,9 +639,10 @@ _header_is_valid (PedDisk const *disk, GuidPartitionTableHeader_t *gpt,
      no smaller than the size of the PartitionEntry structure.
      We also require that be no larger than 1/16th of UINT32_MAX,
      as an additional sanity check.  */
-  uint32_t sope = PED_LE32_TO_CPU (gpt->SizeOfPartitionEntry);
-  if (sope % 8 != 0
-      || sope < sizeof (GuidPartitionEntry_t) || (UINT32_MAX >> 4) < sope)
+  uint32_t pe_size = PED_LE32_TO_CPU (gpt->SizeOfPartitionEntry);
+  if (pe_size % 8 != 0
+      || ! (sizeof (GuidPartitionEntry_t) <= pe_size
+            && pe_size <= (UINT32_MAX >> 4)))
     return 0;
 
   if (PED_LE64_TO_CPU (gpt->MyLBA) != my_lba)

commit 2afb8212f9ce60c160fd94e24e316b7cbb19c061
Author: Jim Meyering <meyering at redhat.com>
Date:   Fri Mar 11 13:35:06 2011 +0100

    gpt: avoid division by zero
    
    * libparted/labels/gpt.c (_header_is_valid): Reject as invalid if
    FirstUsableLBA < 3.
    (gpt_get_max_supported_partition_count): Ensure that we don't divide
    by zero: verify that the GPT header is valid before dividing by its
    "size of partition entry".  Under normal circumstances, the on-disk
    PE size field is reasonable because we have just written it.  However,
    there are two ways it can end up zero: we lose the race when some other
    process pokes a 4-byte 0 into just the right location between when
    we write it and when we re-read the value we're about to divide by.
    Then there's the case that I encountered: using an old USB (8MB) key,
    mklabel gpt failed due to division by zero.  The device reported no
    failure when writing the initial header, yet when reading back that
    very same sector (also successful), parted got all 0 bytes.
    * NEWS (Bug fixes): Mention it.

diff --git a/NEWS b/NEWS
index 604b53d..b7143eb 100644
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,11 @@ GNU parted NEWS                                    -*- outline -*-
   libparted: zero-length devices (other than files) are ignored rather than
   throwing an exception.
 
+  libparted: gpt label creation can no longer divide by zero with a
+  defective device or when a concurrent writer modifies the PE-size
+  bytes in the small interval between the write and subsequent read
+  of the primary GPT header.
+
 ** Changes in behavior
 
   "parted $dev print" now prints information about the device (model, size,
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 54f0785..bfbe7f9 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -660,6 +660,10 @@ _header_is_valid (PedDisk const *disk, GuidPartitionTableHeader_t *gpt,
   if (check_PE_array_CRC (disk, gpt, &crc_match) != 0 || !crc_match)
     return 0;
 
+  PedSector first_usable = PED_LE64_TO_CPU (gpt->FirstUsableLBA);
+  if (first_usable < 3)
+    return 0;
+
   origcrc = gpt->HeaderCRC32;
   gpt->HeaderCRC32 = 0;
   if (pth_crc32 (dev, gpt, &crc) != 0)
@@ -1741,6 +1745,13 @@ gpt_get_max_supported_partition_count (const PedDisk *disk, int *max_n)
   if (pth == NULL)
     return false;
 
+  if (!_header_is_valid (disk, pth, 1))
+    {
+      pth->FirstUsableLBA = 34;
+      pth->SizeOfPartitionEntry
+        = PED_CPU_TO_LE32 (sizeof (GuidPartitionEntry_t));
+    }
+
   *max_n = (disk->dev->sector_size * (pth->FirstUsableLBA - 2)
             / PED_LE32_TO_CPU (pth->SizeOfPartitionEntry));
   pth_free (pth);

commit 7fe0eb2d545f87324353e1ed6384622bcf040bba
Author: Jim Meyering <meyering at redhat.com>
Date:   Mon Mar 7 15:46:42 2011 +0100

    build: enable compilation warnings also for new nilfs2 subdir
    
    * libparted/fs/nilfs2/Makefile.am (AM_CFLAGS): Define.

diff --git a/libparted/fs/nilfs2/Makefile.am b/libparted/fs/nilfs2/Makefile.am
index 9bb87b6..c7cfd68 100644
--- a/libparted/fs/nilfs2/Makefile.am
+++ b/libparted/fs/nilfs2/Makefile.am
@@ -1,5 +1,7 @@
 partedincludedir	= -I$(top_srcdir)/include
 
+AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
+
 noinst_LTLIBRARIES	= libnilfs2.la
 libnilfs2_la_SOURCES	= nilfs2.c
 

commit 8d21e933159f1f0ed53db0a4e28a10d21f5f564c
Author: Jim Meyering <meyering at redhat.com>
Date:   Wed Mar 16 18:11:53 2011 +0100

    nilfs2: remove unused nilfs2_clobber function
    
    * libparted/fs/nilfs2/nilfs2.c (nilfs2_clobber): Remove unused
    function.
    (nilfs2_ops) [clobber]: Always set to NULL.

diff --git a/libparted/fs/nilfs2/nilfs2.c b/libparted/fs/nilfs2/nilfs2.c
index 49634c0..43dd64d 100644
--- a/libparted/fs/nilfs2/nilfs2.c
+++ b/libparted/fs/nilfs2/nilfs2.c
@@ -137,35 +137,9 @@ nilfs2_probe (PedGeometry* geom)
 	return ped_geometry_new(geom->dev, geom->start, length);
 }
 
-#ifndef DISCOVER_ONLY
-static int
-nilfs2_clobber (PedGeometry* geom)
-{
-	char buf[512];
-	int ret[2];
-
-	printf("nilfs2_clobber\n");
-	memset (buf, 0, 512);
-
-	ret[0] = ped_geometry_write (geom, buf, NILFS_SB_OFFSET, 1);
-	ret[1] = ped_geometry_write (geom, buf,
-				     NILFS_SB2_OFFSET(geom->length), 1);
-
-	return ret[0]|ret[1];
-}
-#endif /* !DISCOVER_ONLY */
-
 static PedFileSystemOps nilfs2_ops = {
 	probe:			nilfs2_probe,
-#ifndef DISCOVER_ONLY
- #if 0
-	clobber:		nilfs2_clobber,
- #else
-	clobber:		NULL,
- #endif
-#else
 	clobber:		NULL,
-#endif
 	open:			NULL,
 	create:			NULL,
 	close:			NULL,

commit e2758b3b0b36c6dbf5037c11c2b55c398bdba47a
Author: Jim Meyering <meyering at redhat.com>
Date:   Mon Mar 7 15:44:50 2011 +0100

    maint: avoid shadowing warning
    
    * parted/parted.c (do_mkpart): Rename inner added_ok to add_ok.

diff --git a/parted/parted.c b/parted/parted.c
index c4cf959..4427f0f 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1041,11 +1041,11 @@ do_mkpartfs (PedDevice** dev)
                 ped_exception_leave_all();
 
                 PedConstraint *constraint_any = ped_constraint_any (*dev);
-                bool added_ok = ped_disk_add_partition (disk, part,
+                bool add_ok = ped_disk_add_partition (disk, part,
                                                         constraint_any);
                 ped_constraint_destroy (constraint_any);
 
-                if (!added_ok)
+                if (!add_ok)
                         goto error_remove_part;
 
                 if (!ped_geometry_test_sector_inside(range_start, part->geom.start) ||

commit bd2e00295481481e2e7adfb0f4ccc0ca73a8de31
Author: Jim Meyering <meyering at redhat.com>
Date:   Mon Mar 7 15:42:57 2011 +0100

    build: don't let parted_CFLAGS override our AM_CFLAGS setting
    
    * parted/Makefile.am (parted_CFLAGS): Remove unused (and interfering)
    definition.

diff --git a/parted/Makefile.am b/parted/Makefile.am
index 5838590..7b093c6 100644
--- a/parted/Makefile.am
+++ b/parted/Makefile.am
@@ -36,9 +36,6 @@ version.h: Makefile
 DISTCLEANFILES = version.c version.h
 MAINTAINERCLEANFILES = $(BUILT_SOURCES)
 
-#parted_CFLAGS = -DBUILDINFO='"\"'$(BUILDINFO)'\""'
-parted_CFLAGS = -DBUILDINFO=
-
 parted_LDADD = \
   libver.a \
   $(top_builddir)/libparted/libparted.la \



More information about the Parted-commits mailing list