bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/6] bsd: avoid NULL-deref-on-OOM and an error-path leak


From: Jim Meyering
Subject: [PATCH 1/6] bsd: avoid NULL-deref-on-OOM and an error-path leak
Date: Fri, 27 May 2011 14:52:31 +0200

Coverity spotted these leaks:

>From 3259d570c7e58d317a823994200183501eff7092 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 27 May 2011 14:24:33 +0200
Subject: [PATCH 1/6] bsd: avoid NULL-deref-on-OOM and an error-path leak

* libparted/labels/bsd.c (bsd_read): Don't dereference NULL on OOM.
Don't leak a constraint when failing to add a partition.
---
 libparted/labels/bsd.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/libparted/labels/bsd.c b/libparted/labels/bsd.c
index f3dd9d4..2278a86 100644
--- a/libparted/labels/bsd.c
+++ b/libparted/labels/bsd.c
@@ -277,7 +277,6 @@ bsd_read (PedDisk* disk)
                BSDPartitionData*       bsd_part_data;
                PedSector               start;
                PedSector               end;
-               PedConstraint*          constraint_exact;

                if (!label->d_partitions[i - 1].p_size
                    || !label->d_partitions[i - 1].p_fstype)
@@ -294,10 +293,14 @@ bsd_read (PedDisk* disk)
                part->num = i;
                part->fs_type = ped_file_system_probe (&part->geom);

-               constraint_exact = ped_constraint_exact (&part->geom);
-               if (!ped_disk_add_partition (disk, part, constraint_exact))
+               PedConstraint *constraint_exact
+                       = ped_constraint_exact (&part->geom);
+               if (constraint_exact == NULL)
                        goto error;
+               bool ok = ped_disk_add_partition (disk, part, constraint_exact);
                ped_constraint_destroy (constraint_exact);
+               if (!ok)
+                       goto error;
        }

        return 1;
--
1.7.5.2.660.g9f46c


>From 82affc12511b81f10c65a6bc4437c1682e8eea38 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 27 May 2011 14:27:41 +0200
Subject: [PATCH 2/6] UI: plug a leak

* parted/ui.c (command_line_get_fs_type): Don't leak an FS type name
string.
---
 parted/ui.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/parted/ui.c b/parted/ui.c
index 5255538..7e2db32 100644
--- a/parted/ui.c
+++ b/parted/ui.c
@@ -1082,6 +1082,7 @@ command_line_get_fs_type (const char* prompt, const 
PedFileSystemType*(* value))
                 ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
                                      _("Unknown file system type \"%s\"."),
                                      fs_type_name);
+                free (fs_type_name);
                 return 0;
         }

--
1.7.5.2.660.g9f46c


>From 7ee08acc079d18b371fd8787965f5388b115c893 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 27 May 2011 14:31:45 +0200
Subject: [PATCH 3/6] UI: avoid leak when interactive sector selection matches
 default

* parted/ui.c (command_line_get_fs_type): Don't leak an input "word".
---
 parted/ui.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/parted/ui.c b/parted/ui.c
index 7e2db32..6d2fde1 100644
--- a/parted/ui.c
+++ b/parted/ui.c
@@ -946,6 +946,7 @@ command_line_get_sector (const char* prompt, PedDevice* 
dev, PedSector* value,
                 }

                 free (def_str);
+                free (input);
                 return 1;
         }

--
1.7.5.2.660.g9f46c


>From 861650a39b700f7226d0141ef6a0936eb59a2280 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 27 May 2011 14:35:07 +0200
Subject: [PATCH 4/6] sun: avoid NULL-deref-on-OOM and an error-path leak

* libparted/labels/sun.c (sun_read): Don't dereference NULL on OOM.
Don't leak a constraint when failing to add a partition.
---
 libparted/labels/sun.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/libparted/labels/sun.c b/libparted/labels/sun.c
index 75f7c6e..6148273 100644
--- a/libparted/labels/sun.c
+++ b/libparted/labels/sun.c
@@ -313,7 +313,6 @@ sun_read (PedDisk* disk)
        int i;
        PedPartition* part;
        PedSector end, start, block;
-       PedConstraint* constraint_exact;

        PED_ASSERT (disk != NULL);
        PED_ASSERT (disk->dev != NULL);
@@ -366,10 +365,14 @@ sun_read (PedDisk* disk)
                part->num = i + 1;
                part->fs_type = ped_file_system_probe (&part->geom);

-               constraint_exact = ped_constraint_exact (&part->geom);
-               if (!ped_disk_add_partition (disk, part, constraint_exact))
+               PedConstraint *constraint_exact
+                       = ped_constraint_exact (&part->geom);
+               if (constraint_exact == NULL)
                        goto error;
+               bool ok = ped_disk_add_partition (disk, part, constraint_exact);
                ped_constraint_destroy (constraint_exact);
+               if (!ok)
+                       goto error;
        }

        return 1;
--
1.7.5.2.660.g9f46c


>From e55ca535addd56e0293bb906e5535ab7a352a0e2 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 27 May 2011 14:38:16 +0200
Subject: [PATCH 5/6] mac: avoid NULL-deref-on-OOM and an error-path leak

* libparted/labels/mac.c (mac_read): Don't dereference NULL on OOM.
Don't leak a constraint when failing to add a partition.
---
 libparted/labels/mac.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
index f63f48a..bd756c2 100644
--- a/libparted/labels/mac.c
+++ b/libparted/labels/mac.c
@@ -728,7 +728,6 @@ mac_read (PedDisk* disk)
        PedPartition*           part;
        int                     num;
        PedSector               ghost_size;
-       PedConstraint*          constraint_exact;
        int                     last_part_entry_num = 0;

        PED_ASSERT (disk != NULL);
@@ -795,10 +794,14 @@ mac_read (PedDisk* disk)
                        goto error_delete_all;
                part->num = num;
                part->fs_type = ped_file_system_probe (&part->geom);
-               constraint_exact = ped_constraint_exact (&part->geom);
-               if (!ped_disk_add_partition (disk, part, constraint_exact))
+               PedConstraint *constraint_exact
+                       = ped_constraint_exact (&part->geom);
+               if (constraint_exact == NULL)
                        goto error_delete_all;
+               bool ok = ped_disk_add_partition (disk, part, constraint_exact);
                ped_constraint_destroy (constraint_exact);
+               if (!ok)
+                       goto error_delete_all;

                if (_rawpart_is_partition_map (raw_part)) {
                        if (mac_disk_data->part_map_entry_num
--
1.7.5.2.660.g9f46c


>From 417eadba5b12de3ba2a018f2423a02bae7d0bd18 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 27 May 2011 14:45:19 +0200
Subject: [PATCH 6/6] amiga: avoid NULL-deref-on-OOM and an error-path leak

* libparted/labels/rdb.c (amiga_read): Don't dereference NULL on OOM.
Don't leak a constraint when failing to add a partition.
---
 libparted/labels/rdb.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/libparted/labels/rdb.c b/libparted/labels/rdb.c
index 98c8fb6..5db3787 100644
--- a/libparted/labels/rdb.c
+++ b/libparted/labels/rdb.c
@@ -509,7 +509,6 @@ amiga_read (PedDisk* disk)
        {
                PedPartition *part;
                PedSector start, end;
-               PedConstraint *constraint_exact;

                /* Let's look for loops in the partition table */
                if (_amiga_loop_check(partblock, partlist, i)) {
@@ -542,13 +541,17 @@ amiga_read (PedDisk* disk)
                /* Let's probe what file system is present on the disk */
                part->fs_type = ped_file_system_probe (&part->geom);

-               constraint_exact = ped_constraint_exact (&part->geom);
-               if (!ped_disk_add_partition (disk, part, constraint_exact)) {
+               PedConstraint *constraint_exact
+                       = ped_constraint_exact (&part->geom);
+               if (constraint_exact == NULL)
+                       return 0;
+               bool ok = ped_disk_add_partition (disk, part, constraint_exact);
+               ped_constraint_destroy (constraint_exact);
+               if (!ok) {
                        ped_partition_destroy(part);
                        free(partition);
                        return 0;
                }
-               ped_constraint_destroy (constraint_exact);
        }
        free(partition);
        return 1;
--
1.7.5.2.660.g9f46c



reply via email to

[Prev in Thread] Current Thread [Next in Thread]