[gparted] Correctly const and assert detect_filesystem() parameters (#152)



commit 8280f3eedccc7c90b0b026357537bed74dd1b734
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sat Apr 10 14:19:32 2021 +0100

    Correctly const and assert detect_filesystem() parameters (#152)
    
    As discussed in the previous commit "Don't crash probing libparted
    unrecognised encrypted file system (#152)", detect_filesystem() accepted
    a NULL lp_device pointer and dereferenced it leading to the crash.
    Document the requirement for lp_device parameter to be non-NULL via an
    assert and also correctly const the parameters.
    
    This forces needing to const the lp_partition parameter to
    get_partition_path() too.  Also assert it's non-NULL requirement.
    
    Closes #152 - GParted crashed when trying to probe an encrypted
                  partition containing content that libparted doesn't
                  recognise

 include/GParted_Core.h |  6 +++---
 src/GParted_Core.cc    | 11 ++++++++---
 2 files changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index 18f4b686..0db4aa73 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -82,7 +82,7 @@ public:
 private:
        //detectionstuff..
        void set_thread_status_message( Glib::ustring msg ) ;
-       static Glib::ustring get_partition_path( PedPartition * lp_partition );
+       static Glib::ustring get_partition_path(const PedPartition *lp_partition);
        void set_device_from_disk( Device & device, const Glib::ustring & device_path );
        void set_device_serial_number( Device & device );
        void set_device_partitions( Device & device, PedDevice* lp_device, PedDisk* lp_disk ) ;
@@ -93,8 +93,8 @@ private:
        static FSType detect_filesystem_in_encryption_mapping(const Glib::ustring& path,
                                                              std::vector<Glib::ustring>& messages);
        static FSType detect_filesystem_internal(const Glib::ustring& path, Byte_Value sector_size);
-       static FSType detect_filesystem( PedDevice * lp_device, PedPartition * lp_partition,
-                                        std::vector<Glib::ustring> & messages );
+       static FSType detect_filesystem(const PedDevice *lp_device, const PedPartition *lp_partition,
+                                       std::vector<Glib::ustring> &messages);
        void read_label( Partition & partition ) ;
        void read_uuid( Partition & partition ) ;
        void set_mountpoints( Partition & partition );
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 4fd27743..6d6885ac 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -618,8 +618,10 @@ std::map<Glib::ustring, bool> GParted_Core::get_available_flags( const Partition
 
 //private functions...
 
-Glib::ustring GParted_Core::get_partition_path( PedPartition * lp_partition )
+Glib::ustring GParted_Core::get_partition_path(const PedPartition *lp_partition)
 {
+       g_assert(lp_partition != NULL);  // Bug: Not initialised by suitable ped_disk_*partition*() call
+
        char * lp_path;  //we have to free the result of ped_partition_get_path()
        Glib::ustring partition_path = "Partition path not found";
 
@@ -1218,9 +1220,12 @@ FSType GParted_Core::detect_filesystem_internal(const Glib::ustring& path, Byte_
        return fstype;
 }
 
-FSType GParted_Core::detect_filesystem( PedDevice * lp_device, PedPartition * lp_partition,
-                                        std::vector<Glib::ustring> & messages )
+
+FSType GParted_Core::detect_filesystem(const PedDevice *lp_device, const PedPartition *lp_partition,
+                                       std::vector<Glib::ustring> &messages)
 {
+       g_assert(lp_device != NULL);  // Bug: Not initialised by call to ped_device_get() or 
ped_device_get_next()
+
        Glib::ustring fsname = "";
        Glib::ustring path;
        DMRaid dmraid;


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