[gparted] Fix uninitialised read when pasting into an existing partition



commit ea4b77eb01a1e1357ab3ef89a2e7f46a20504fd1
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri Mar 23 15:51:08 2012 +0000

    Fix uninitialised read when pasting into an existing partition
    
    GParted_Core::set_device_partitions() creates and initialises the
    partition objects based on the partitions on the disk using
    partition.Reset() and partition.Set().  These methods never set the
    alignment attribute.
    
    Copy and pasting into an existing partition calls GParted_Core::
    snap_to_alignment() to adjust the start and end of the newly created
    in memory partition object.  When pasting into unallocated space the
    user has selected the required alignment and this is exactly what is
    needed.  However when pasting into an existing partition the in memory
    partition object should always match the actual partition boundaries on
    disk.  Unfortunately the partition boundaries are adjusted based on
    reading the uninitialised alignment attribute.
    
    Initialise the alignment attribute of newly created partition objects to
    ALIGN_STRICT.  Also, when pasting into an existing partition set the
    alignment of that partition object to ALIGN_STRICT so that no boundary
    adjustment is performed.
    
    valgrind:
    ==6845== Conditional jump or move depends on uninitialised value(s)
    ==6845==    at 0x80C779A: GParted::GParted_Core::snap_to_alignment(...) (GParted_Core.cc:566)
    ==6845==    by 0x810C115: GParted::Win_GParted::Add_Operation(...) (Win_GParted.cc:692)
    ==6845==    by 0x8110499: GParted::Win_GParted::activate_paste() (Win_GParted.cc:1649)
    ...
    ==6845== Conditional jump or move depends on uninitialised value(s)
    ==6845==    at 0x80C77A8: GParted::GParted_Core::snap_to_alignment(...) (GParted_Core.cc:568)
    ==6845==    by 0x810C115: GParted::Win_GParted::Add_Operation(...) (Win_GParted.cc:692)
    ==6845==    by 0x8110499: GParted::Win_GParted::activate_paste() (Win_GParted.cc:1649)
    
    GParted_Core.cc:
       562  bool GParted_Core::snap_to_alignment( const Device & device, Partition & partition, Glib::ustring & error )
       563  {
       564          bool rc = true ;
       565
    >> 566          if ( partition .alignment == ALIGN_CYLINDER )
       567                  rc = snap_to_cylinder( device, partition, error ) ;
    >> 568          else if ( partition .alignment == ALIGN_MEBIBYTE )
       569                  rc = snap_to_mebibyte( device, partition, error ) ;
       570
    
    Closes Bug #672654 - Pasting into an existing partition may shrink
                         GParted's representation of it

 src/Partition.cc   |    1 +
 src/Win_GParted.cc |    4 ++++
 2 files changed, 5 insertions(+), 0 deletions(-)
---
diff --git a/src/Partition.cc b/src/Partition.cc
index 452e487..620fdee 100644
--- a/src/Partition.cc
+++ b/src/Partition.cc
@@ -39,6 +39,7 @@ void Partition::Reset()
 	messages .clear() ;
 	status = GParted::STAT_REAL ;
 	type = GParted::TYPE_UNALLOCATED ;
+	alignment = ALIGN_STRICT ;
 	filesystem = GParted::FS_UNALLOCATED ;
 	label .clear() ;
 	uuid .clear() ;
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 7fa0ced..06b38b9 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -683,6 +683,9 @@ void Win_GParted::Add_Operation( Operation * operation, int index )
 	if ( operation )
 	{ 
 		Glib::ustring error ;
+		//Add any of the listed operations without further checking, but
+		//  for the other operations (_CREATE, _RESIZE_MOVE and _COPY)
+		//  ensure the partition is correctly aligned.
 		//FIXME: this is becoming a mess.. maybe it's better to check if partition_new > 0
 		if ( operation ->type == OPERATION_DELETE ||
 		     operation ->type == OPERATION_FORMAT ||
@@ -1633,6 +1636,7 @@ void Win_GParted::activate_paste()
 	else
 	{
 		Partition partition_new = selected_partition ;
+		partition_new .alignment = ALIGN_STRICT ;
 		partition_new .filesystem = copied_partition .filesystem ;
 		partition_new .label = copied_partition .label ;
 		partition_new .uuid = copied_partition .uuid ;



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