[PATCH] dasd: avoid NULL-dereference via disk->type->ops->partition_check
Jim Meyering
meyering at redhat.com
Mon Nov 23 20:46:17 UTC 2009
Commit f387fee8 added the new ops->partition_check() function,
and a <type>_partition_check function for each partition table
format _except_ dasd. This change adds one for dasd, too.
* libparted/labels/dasd.c: Include "pt-tools.h".
(dasd_partition_check): New function.
* libparted/labels/pt-tools.c (ptt_partition_max_start_len): Add "dasd"
to the list of partition table type names for which the 32-bit
limits on starting sector and partition length apply.
Correct a comment.
Considering the 32-bit fields in "struct fdasd_hd_geometry",
it is safe to assume that larger offset or size is not possible.
---
libparted/labels/dasd.c | 8 ++++++++
libparted/labels/pt-tools.c | 4 ++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c
index 3f8147d..fc0695c 100644
--- a/libparted/labels/dasd.c
+++ b/libparted/labels/dasd.c
@@ -48,6 +48,7 @@
#endif /* ENABLE_NLS */
#include "misc.h"
+#include "pt-tools.h"
#define PARTITION_LINUX_SWAP 0x82
#define PARTITION_LINUX 0x83
@@ -106,6 +107,12 @@ static int dasd_partition_set_system (PedPartition* part,
const PedFileSystemType* fs_type);
static int dasd_alloc_metadata (PedDisk* disk);
+static bool
+dasd_partition_check (const PedPartition *part)
+{
+ return ptt_partition_max_start_len ("dasd", part);
+}
+
static PedDiskOps dasd_disk_ops = {
probe: dasd_probe,
clobber: dasd_clobber,
@@ -132,6 +139,7 @@ static PedDiskOps dasd_disk_ops = {
get_max_primary_partition_count: dasd_get_max_primary_partition_count,
get_max_supported_partition_count: dasd_get_max_supported_partition_count,
get_partition_alignment: dasd_get_partition_alignment,
+ partition_check: dasd_partition_check,
};
static PedDiskType dasd_disk_type = {
diff --git a/libparted/labels/pt-tools.c b/libparted/labels/pt-tools.c
index 622cedd..8afec77 100644
--- a/libparted/labels/pt-tools.c
+++ b/libparted/labels/pt-tools.c
@@ -98,14 +98,14 @@ ptt_clear_sectors (PedDevice *dev, PedSector start, PedSector n)
int
ptt_partition_max_start_len (char const *label_type, const PedPartition *part)
{
- static char const *const max_32[] = {"msdos", "dvh"};
+ static char const *const max_32[] = {"msdos", "dvh", "dasd"};
unsigned int i;
for (i = 0; i < sizeof max_32 / sizeof *max_32; i++)
{
if (strcmp (label_type, max_32[i]) == 0)
{
- /* The starting sector length must fit in 32 bytes. */
+ /* The length (in sectors) must fit in 32 bytes. */
if (part->geom.length > UINT32_MAX)
{
ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
--
1.6.6.rc0.203.g7074f
More information about the parted-devel
mailing list