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

Jim Meyering meyering at alioth.debian.org
Sat May 31 14:59:09 UTC 2008


 libparted/device.c     |   10 +++++++---
 libparted/labels/gpt.c |   22 ++++++++++++++++------
 parted/parted.c        |   49 +++++++++++++++++++++++++------------------------
 3 files changed, 48 insertions(+), 33 deletions(-)

New commits:
commit c675f8f7e4c66687235154b4f491ec5fb94bc915
Author: Jim Meyering <meyering at redhat.com>
Date:   Fri May 30 21:10:06 2008 +0200

    gpt_write: fix a write-uninitialized error
    
    * libparted/labels/gpt.c (gpt_partition_new):
      ==32570== Syscall param write(buf) points to uninitialised byte(s)
      ==32570==    at 0x36CF8D6540: __write_nocancel (in /lib64/libc-2.8.so)
      ==32570==    by 0x443D29: linux_write (linux.c:1642)
      ==32570==    by 0x414E4E: ped_device_write (device.c:370)
      ==32570==    by 0x4404CE: gpt_write (gpt.c:1091)
      ==32570==    by 0x418F16: ped_disk_commit_to_dev (disk.c:486)
      ==32570==    by 0x418F5C: ped_disk_commit (disk.c:509)
      ==32570==    by 0x40BAD6: do_mkpartfs (parted.c:981)
      ==32570==    by 0x40A035: command_run (command.c:139)
      ==32570==    by 0x412150: non_interactive_mode (ui.c:1540)
      ==32570==    by 0x40EE83: main (parted.c:2487)
      ==32570==  Address 0x501b63a is 58 bytes inside a block of size 16,384 alloc'd
      ==32570==    at 0x4A04FC0: memalign (vg_replace_malloc.c:460)
      ==32570==    by 0x4A0507A: posix_memalign (vg_replace_malloc.c:569)
      ==32570==    by 0x443CED: linux_write (linux.c:1637)
      ==32570==    by 0x414E4E: ped_device_write (device.c:370)
      ==32570==    by 0x4404CE: gpt_write (gpt.c:1091)
      ==32570==    by 0x418F16: ped_disk_commit_to_dev (disk.c:486)
      ==32570==    by 0x418F5C: ped_disk_commit (disk.c:509)
      ==32570==    by 0x40BAD6: do_mkpartfs (parted.c:981)
      ==32570==    by 0x40A035: command_run (command.c:139)
      ==32570==    by 0x412150: non_interactive_mode (ui.c:1540)
      ==32570==    by 0x40EE83: main (parted.c:2487)
    
      reproduce with this:
      dev=f
      dd if=/dev/null of=$dev bs=1 seek=30M 2>/dev/null
      ./parted -s $dev mklabel gpt
      valgrind ./parted -s $dev mkpartfs primary ext2 0 16795000B

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index fd9780c..01046a3 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1154,7 +1154,7 @@ gpt_partition_new (const PedDisk* disk,
         gpt_part_data->msftres = 0;
 	uuid_generate ((unsigned char*) &gpt_part_data->uuid);
 	swap_uuid_and_efi_guid((unsigned char*)(&gpt_part_data->uuid));
-	strcpy (gpt_part_data->name, "");
+	memset (gpt_part_data->name, 0, sizeof gpt_part_data->name);
 	return part;
 
 error_free_part:

commit 67a1a3b561131223a7f0cbf4324a71d82838f035
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu May 29 22:35:06 2008 +0200

    plug leaks in do_print
    
    * parted/parted.c (do_print):
    25 bytes in 8 blocks are definitely lost...
       at 0x4A0739E: malloc (vg_replace_malloc.c:207)
       by 0x416E67: ped_malloc (libparted.c:234)
       by 0x41751F: ped_strdup (unit.c:179)
       by 0x417778: ped_unit_format_custom_byte (unit.c:220)
       by 0x417A90: ped_unit_format (unit.c:297)
       by 0x40CD85: do_print (parted.c:1517)
       by 0x40A035: command_run (command.c:139)
       by 0x41210C: non_interactive_mode (ui.c:1540)
       by 0x40EE41: main (parted.c:2482)
    
    10 bytes in 4 blocks are definitely lost...
       at 0x4A0739E: malloc (vg_replace_malloc.c:207)
       by 0x416E9B: ped_malloc (libparted.c:234)
       by 0x417553: ped_strdup (unit.c:179)
       by 0x4177AC: ped_unit_format_custom_byte (unit.c:220)
       by 0x417AC4: ped_unit_format (unit.c:297)
       by 0x40CE34: do_print (parted.c:1527)
       by 0x40A035: command_run (command.c:139)
       by 0x412140: non_interactive_mode (ui.c:1540)
       by 0x40EE75: main (parted.c:2485)

diff --git a/parted/parted.c b/parted/parted.c
index 4f04332..4af72ac 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1508,15 +1508,20 @@ do_print (PedDevice** dev)
                 else
                     fputs ("1:", stdout);
 
-                printf ("%s:", ped_unit_format (*dev, part->geom.start));
-                printf ("%s:", ped_unit_format_byte (
-                                *dev,
-                                (part->geom.end + 1) * 
-                                (*dev)->sector_size - 1));
-
-                if (ped_unit_get_default() != PED_UNIT_CHS)
-                    printf ("%s:", ped_unit_format (*dev,
-                                                    part->geom.length));
+                char *s = ped_unit_format (*dev, part->geom.start);
+                printf ("%s:", s);
+                free (s);
+                s = ped_unit_format_byte (*dev,
+                                          (part->geom.end + 1) *
+                                          (*dev)->sector_size - 1);
+                printf ("%s:", s);
+                free (s);
+
+                if (ped_unit_get_default() != PED_UNIT_CHS) {
+                    s = ped_unit_format (*dev, part->geom.length);
+                    printf ("%s:", s);
+                    free (s);
+                }
                     
                 if (!(part->type & PED_PARTITION_FREESPACE)) {
 

commit ee28997684058ab5bc071de072cf4dfcfeccb661
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu May 29 21:48:14 2008 +0200

    plug two more leaks in gpt_write
    
    * libparted/labels/gpt.c (gpt_write):
    1,024 bytes in 2 blocks are definitely lost...
       at 0x4A0739E: malloc (vg_replace_malloc.c:207)
       by 0x416F1B: ped_malloc (libparted.c:270)
       by 0x43E967: pth_get_raw (gpt.c:334)
       by 0x44039D: gpt_write (gpt.c:1067)
       by 0x418F9A: ped_disk_commit_to_dev (disk.c:486)
       by 0x418FE0: ped_disk_commit (disk.c:509)
       by 0x40AF7A: do_mklabel (parted.c:622)
       by 0x40A055: command_run (command.c:139)
       by 0x4121A4: non_interactive_mode (ui.c:1540)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 3343c3a..fd9780c 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -38,6 +38,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <uuid/uuid.h>
+#include <stdbool.h>
 
 #if ENABLE_NLS
 #  include <libintl.h>
@@ -1064,18 +1065,24 @@ gpt_write(const PedDisk * disk)
 
 	/* Write PTH and PTEs */
 	_generate_header (disk, 0, ptes_crc, &gpt);
-        pth_raw = pth_get_raw (disk->dev, gpt);
-        pth_free (gpt);
-	if (!ped_device_write (disk->dev, pth_raw, 1, 1))
+	pth_raw = pth_get_raw (disk->dev, gpt);
+	pth_free (gpt);
+	bool write_ok = ped_device_write (disk->dev, pth_raw, 1, 1);
+	free (pth_raw);
+	if (!write_ok)
 		goto error_free_ptes;
-	if (!ped_device_write (disk->dev, ptes, 2, ptes_size / disk->dev->sector_size))
+	if (!ped_device_write (disk->dev, ptes, 2,
+			       ptes_size / disk->dev->sector_size))
 		goto error_free_ptes;
 
 	/* Write Alternate PTH & PTEs */
 	_generate_header (disk, 1, ptes_crc, &gpt);
         pth_raw = pth_get_raw (disk->dev, gpt);
         pth_free (gpt);
-	if (!ped_device_write (disk->dev, pth_raw, disk->dev->length - 1, 1))
+	write_ok = ped_device_write (disk->dev, pth_raw,
+				     disk->dev->length - 1, 1);
+	free (pth_raw);
+	if (!write_ok)
 		goto error_free_ptes;
 	if (!ped_device_write (disk->dev, ptes,
 			       disk->dev->length - 1 - ptes_size / disk->dev->sector_size,

commit bb6bada67449f0b15339342e5066762a74663ce5
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu May 29 20:53:08 2008 +0200

    plug a blatant leak in gpt_write
    
    * libparted/labels/gpt.c (gpt_write):
    1,536 bytes in 3 blocks are definitely lost in loss record 9 of 11
       at 0x4A0739E: malloc (vg_replace_malloc.c:207)
       by 0x416F1B: ped_malloc (libparted.c:270)
       by 0x44021F: gpt_write (gpt.c:1036)
       by 0x418F9A: ped_disk_commit_to_dev (disk.c:486)
       by 0x418FE0: ped_disk_commit (disk.c:509)
       by 0x40AF7A: do_mklabel (parted.c:622)
       by 0x40A055: command_run (command.c:139)
       by 0x4121A4: non_interactive_mode (ui.c:1540)
       by 0x40EED8: main (parted.c:2499)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 2d2c82c..3343c3a 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1033,7 +1033,7 @@ gpt_write(const PedDisk * disk)
 	GPTDiskData* gpt_disk_data;
 	GuidPartitionEntry_t* ptes;
 	uint32_t ptes_crc;
-        uint8_t* pth_raw = ped_malloc (pth_get_size (disk->dev));
+	uint8_t* pth_raw;
 	GuidPartitionTableHeader_t* gpt;
 	PedPartition* part;
 	int ptes_size;

commit 88b1ba525ee65d527f408363041e143c6a1d1b35
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu May 29 20:47:44 2008 +0200

    plug leaks in gpt_write
    
    * libparted/labels/gpt.c (gpt_write):
    6,674 bytes in 11 blocks are definitely lost...
      at 0x4A0739E: malloc (vg_replace_malloc.c:207)
      by 0x416F1B: ped_malloc (libparted.c:270)
      by 0x43E76D: pth_new (gpt.c:289)
      by 0x43E7E2: pth_new_zeroed (gpt.c:298)
      by 0x43FF61: _generate_header (gpt.c:970)
      by 0x440434: gpt_write (gpt.c:1074)
      by 0x418F9A: ped_disk_commit_to_dev (disk.c:486)
      by 0x418FE0: ped_disk_commit (disk.c:509)
      by 0x40BB35: do_mkpartfs (parted.c:990)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index ca48f27..2d2c82c 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1065,6 +1065,7 @@ gpt_write(const PedDisk * disk)
 	/* Write PTH and PTEs */
 	_generate_header (disk, 0, ptes_crc, &gpt);
         pth_raw = pth_get_raw (disk->dev, gpt);
+        pth_free (gpt);
 	if (!ped_device_write (disk->dev, pth_raw, 1, 1))
 		goto error_free_ptes;
 	if (!ped_device_write (disk->dev, ptes, 2, ptes_size / disk->dev->sector_size))
@@ -1073,6 +1074,7 @@ gpt_write(const PedDisk * disk)
 	/* Write Alternate PTH & PTEs */
 	_generate_header (disk, 1, ptes_crc, &gpt);
         pth_raw = pth_get_raw (disk->dev, gpt);
+        pth_free (gpt);
 	if (!ped_device_write (disk->dev, pth_raw, disk->dev->length - 1, 1))
 		goto error_free_ptes;
 	if (!ped_device_write (disk->dev, ptes,

commit 1a7052ba77905fdfa036fc800bce7a2fb8de7d69
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu May 29 20:38:13 2008 +0200

    plug a leak in gpt_read
    
    * libparted/labels/gpt.c (gpt_read):
    7,195 bytes in 13 blocks are definitely lost...
       at 0x4A0739E: malloc (vg_replace_malloc.c:207)
       by 0x416F1B: ped_malloc (libparted.c:270)
       by 0x43E759: pth_new (gpt.c:287)
       by 0x43E83C: pth_new_from_raw (gpt.c:310)
       by 0x43F329: _read_header (gpt.c:627)
       by 0x43FB31: gpt_read (gpt.c:826)
       by 0x41882B: ped_disk_new (disk.c:210)
       by 0x40B773: do_mkpartfs (parted.c:884)
       by 0x40A055: command_run (command.c:139)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 8bb9554..ca48f27 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -924,6 +924,7 @@ gpt_read (PedDisk * disk)
 		ped_disk_commit_to_dev (disk);
 #endif
 
+	pth_free (gpt);
 	return 1;
 
 error_delete_all:

commit 9edcca96a2b53d8fd4da32d881888d7bcb95a043
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu May 29 19:38:09 2008 +0200

    plug leak in ped_device_get_constraint
    
    496 (208 direct, 288 indirect) bytes in 5 blocks are definitely lost...
       at 0x4A0739E: malloc (vg_replace_malloc.c:207)
       by 0x416EDF: ped_malloc (libparted.c:270)
       by 0x41CB40: ped_geometry_new (geom.c:79)
       by 0x415167: ped_device_get_constraint (device.c:438)
       by 0x40B928: do_mkpartfs (parted.c:927)
       by 0x40A055: command_run (command.c:139)
       by 0x41217C: non_interactive_mode (ui.c:1540)
       by 0x40EEB1: main (parted.c:2497)

diff --git a/libparted/device.c b/libparted/device.c
index 6595572..b951dd2 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -431,12 +431,15 @@ ped_device_get_constraint (PedDevice* dev)
 
         PedAlignment* start_align = ped_alignment_new (multiplier, multiplier);
         
+        PedGeometry *s, *e;
         PedConstraint* c = ped_constraint_new (
                                 start_align, ped_alignment_any,
-                                ped_geometry_new (dev, 0, dev->length),
-                                ped_geometry_new (dev, 0, dev->length),
+                                s = ped_geometry_new (dev, 0, dev->length),
+                                e = ped_geometry_new (dev, 0, dev->length),
                                 1, dev->length);
 
+        free (s);
+        free (e);
         free (start_align);
         return c;
 }

commit ffaf0b817515db29b27269b5b906c79bb6a72d7c
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu May 29 19:36:02 2008 +0200

    plug leaks in parted.c
    
    432 (144 direct, 288 indirect) bytes in 3 blocks are definitely lost...
       at 0x4A0739E: malloc (vg_replace_malloc.c:207)
       by 0x416EF3: ped_malloc (libparted.c:270)
       by 0x41D9D2: ped_constraint_new (constraint.c:100)
       by 0x4151A4: ped_device_get_constraint (device.c:439)
       by 0x40B928: do_mkpartfs (parted.c:927)
       by 0x40A055: command_run (command.c:139)
       by 0x41217C: non_interactive_mode (ui.c:1540)
       by 0x40EEB1: main (parted.c:2497)
    
    And another:
    
    * parted/parted.c (do_mkpartfs): Here's one of the signatures:
    288 (96 direct, 192 indirect) bytes in 2 blocks are definitely lost...
       at 0x4A0739E: malloc (vg_replace_malloc.c:207)
       by 0x416EF3: ped_malloc (libparted.c:270)
       by 0x41D9D2: ped_constraint_new (constraint.c:100)
       by 0x41DE2C: ped_constraint_intersect (constraint.c:232)
       by 0x40B971: do_mkpartfs (parted.c:930)
       by 0x40A055: command_run (command.c:139)
       by 0x41217C: non_interactive_mode (ui.c:1540)
       by 0x40EEB1: main (parted.c:2497)
    
    * parted/parted.c (do_mkpart): Likewise for this function,
    since do_mkpart is nearly identical to do_mkpartfs.

diff --git a/parted/parted.c b/parted/parted.c
index 4e16f92..4f04332 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -17,6 +17,7 @@
 */
 
 #include <config.h>
+#include <stdbool.h>
 
 #include "closeout.h"
 #include "configmake.h"
@@ -757,12 +758,16 @@ do_mkpart (PedDevice** dev)
 
         final_constraint = ped_constraint_intersect (user_constraint,
                         dev_constraint);
+        ped_constraint_destroy (user_constraint);
+        ped_constraint_destroy (dev_constraint);
         if (!final_constraint)
                 goto error_destroy_simple_constraints;
 
         /* subject to partition constraint */
         ped_exception_fetch_all();
-        if (!ped_disk_add_partition (disk, part, final_constraint)) {
+        bool added_ok = ped_disk_add_partition (disk, part, final_constraint);
+        ped_constraint_destroy (final_constraint);
+        if (!added_ok) {
                 ped_exception_leave_all();
                
                 if (ped_disk_add_partition (disk, part,
@@ -810,10 +815,6 @@ do_mkpart (PedDevice** dev)
                 goto error_destroy_disk;
         
         /* clean up */
-        ped_constraint_destroy (final_constraint);
-        ped_constraint_destroy (user_constraint);
-        ped_constraint_destroy (dev_constraint);
-
         ped_disk_destroy (disk);
         
         if (range_start != NULL)
@@ -833,10 +834,7 @@ do_mkpart (PedDevice** dev)
 
 error_remove_part:
         ped_disk_remove_partition (disk, part);
-        ped_constraint_destroy (final_constraint);
 error_destroy_simple_constraints:
-        ped_constraint_destroy (user_constraint);
-        ped_constraint_destroy (dev_constraint);
         ped_partition_destroy (part);
 error_destroy_disk:
         ped_disk_destroy (disk);
@@ -920,12 +918,16 @@ do_mkpartfs (PedDevice** dev)
 
         final_constraint = ped_constraint_intersect (user_constraint,
                                                      dev_constraint);
+        ped_constraint_destroy (user_constraint);
+        ped_constraint_destroy (dev_constraint);
         if (!final_constraint)
                 goto error_destroy_simple_constraints;
 
         /* subject to partition constraint */
         ped_exception_fetch_all();
-        if (!ped_disk_add_partition (disk, part, final_constraint)) {
+	bool added_ok = ped_disk_add_partition (disk, part, final_constraint);
+        ped_constraint_destroy (final_constraint);
+        if (!added_ok) {
                 ped_exception_leave_all();
                
                 if (ped_disk_add_partition (disk, part,
@@ -977,9 +979,6 @@ do_mkpartfs (PedDevice** dev)
                 goto error_destroy_disk;
 
         /* clean up */
-        ped_constraint_destroy (final_constraint);
-        ped_constraint_destroy (user_constraint);
-        ped_constraint_destroy (dev_constraint);
 
         ped_disk_destroy (disk);
 
@@ -1000,10 +999,7 @@ do_mkpartfs (PedDevice** dev)
 
 error_remove_part:
         ped_disk_remove_partition (disk, part);
-        ped_constraint_destroy (final_constraint);
 error_destroy_simple_constraints:
-        ped_constraint_destroy (user_constraint);
-        ped_constraint_destroy (dev_constraint);
         ped_partition_destroy (part);
 error_destroy_disk:
         ped_disk_destroy (disk);

commit 9f1c01c1f2931ffd0cff29ee0646f9db1c8978ba
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu May 29 15:47:21 2008 +0200

    plug a leak in ped_device_get_constraint
    
    * libparted/device.c (ped_device_get_constraint):
    512 (224 direct, 288 indirect) bytes in 6 blocks are definitely lost...
      malloc (vg_replace_malloc.c:207)
      ped_malloc (libparted.c:270)
      ped_alignment_new (natmath.c:153)
      ped_device_get_constraint (device.c:432)
      do_mkpartfs (parted.c:927)
      command_run (command.c:139)
      non_interactive_mode (ui.c:1540)
      main (parted.c:2497)

diff --git a/libparted/device.c b/libparted/device.c
index ac2a5cd..6595572 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 1999 - 2001, 2005, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1999 - 2001, 2005, 2007-2008 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
@@ -437,6 +437,7 @@ ped_device_get_constraint (PedDevice* dev)
                                 ped_geometry_new (dev, 0, dev->length),
                                 1, dev->length);
 
+        free (start_align);
         return c;
 }
 



More information about the Parted-commits mailing list