[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/4] gpt: don't misbehave with e.g., a 9-entry partition array
From: |
Jim Meyering |
Subject: |
[PATCH 2/4] gpt: don't misbehave with e.g., a 9-entry partition array |
Date: |
Thu, 3 Nov 2011 22:18:56 +0100 |
From: Jim Meyering <address@hidden>
* libparted/labels/gpt.c (_generate_header): Correct size of
partition array entries to round up to nearest multiple of
sector size, so that we set gpt->PartitionEntryLBA correctly
also when the number of partition entries is not a multiple
of sector_size / 128. Problem diagnosed by Robert Herndon
in http://thread.gmane.org/gmane.comp.gnu.parted.bugs/10173.
---
NEWS | 5 +++++
libparted/labels/gpt.c | 8 +++++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/NEWS b/NEWS
index b043ba1..c6e22f0 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,11 @@ GNU parted NEWS -*-
outline -*-
libparted: gpt_disk_duplicate now copies the flags over to the new
disk object. Previously the flags would be undefined.
+ libparted can now read partition tables with a number of partition
+ array entries that is different from the default of 128. Before,
+ it would fail to recognize them and could even read beyond the end
+ of a heap-allocated buffer.
+
libparted: no longer aborts (failed assertion) due to a nilfs2_probe bug
[bug introduced in parted-2.4 with the addition of nilfs2 support]
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index e239a2d..454a177 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1137,13 +1137,15 @@ _generate_header (const PedDisk *disk, int alternate,
uint32_t ptes_crc,
if (alternate)
{
- PedSector ptes_size = gpt_disk_data->entry_count
- * sizeof (GuidPartitionEntry_t) / disk->dev->sector_size;
+ size_t ss = disk->dev->sector_size;
+ PedSector ptes_bytes = (gpt_disk_data->entry_count
+ * sizeof (GuidPartitionEntry_t));
+ PedSector ptes_sectors = (ptes_bytes + ss - 1) / ss;
gpt->MyLBA = PED_CPU_TO_LE64 (disk->dev->length - 1);
gpt->AlternateLBA = PED_CPU_TO_LE64 (1);
gpt->PartitionEntryLBA
- = PED_CPU_TO_LE64 (disk->dev->length - 1 - ptes_size);
+ = PED_CPU_TO_LE64 (disk->dev->length - 1 - ptes_sectors);
}
else
{
--
1.7.8.rc0.32.g87bf9
- GPT: don't misbehave with e.g., a 9-entry partition, Jim Meyering, 2011/11/03
- [PATCH 1/4] gpt: prepare for tables with n_partition_array_entries != 128, Jim Meyering, 2011/11/03
- [PATCH 2/4] gpt: don't misbehave with e.g., a 9-entry partition array,
Jim Meyering <=
- [PATCH 3/4] tests: rewrite/complete GPT-munging perl script, Jim Meyering, 2011/11/03
- [PATCH 4/4] tests: exercise the "GPT vs other-sized partition entry arrays" fixes, Jim Meyering, 2011/11/03
- Re: GPT: don't misbehave with e.g., a 9-entry partition, Seth Goldberg, 2011/11/03
- Re: GPT: don't misbehave with e.g., a 9-entry partition, Jim Meyering, 2011/11/04