Prevent core dump with non-existent or invalid command line named device (#756434)

Naming a non-existent or invalid disk device on the command line causes
GParted to dump core.  Non-existent device looks like this:

    # ./gpartedbin /dev/does-not-exist
    ======================
    libparted : 2.4
    ======================
    Could not stat device /dev/does-not-exist - No such file or directory.
    Could not stat device /dev/does-not-exist - No such file or directory.
    Backtrace has 10 calls on stack:
      10: /lib64/libparted.so.0(ped_assert+0x31) [0x7fcfd10b3e61]
      9: /lib64/libparted.so.0(+0x3fdfc12a0c) [0x7fcfd10b4a0c]
      8: /home/mike/bin/gpartedbin-0.23.0-master-63-g23b5ba4() [0x455028]
      7: /home/mike/bin/gpartedbin-0.23.0-master-63-g23b5ba4() [0x455090]
      6: /home/mike/bin/gpartedbin-0.23.0-master-63-g23b5ba4() [0x4550d5]
      5: /home/mike/bin/gpartedbin-0.23.0-master-63-g23b5ba4() [0x46723f]
      4: /usr/lib64/libglibmm-2.4.so.1() [0x3ff5834a8d]
      3: /lib64/libglib-2.0.so.0() [0x3fe086a374]
      2: /lib64/libpthread.so.0() [0x3fdf407a51]
      1: /lib64/libc.so.6(clone+0x6d) [0x3fdf0e893d]
    Assertion (dev != NULL) at device.c:227 in function ped_device_open() failed.
    Aborted (core dumped)

And with an invalid device the output looks like this:

    # ./gpartedbin /dev/zero
    ======================
    libparted : 2.4
    ======================
    The device /dev/zero is so small that it cannot possibly store a file system or partition table.  Perhaps you selected the wrong device?
    Error fsyncing/closing /dev/zero: Invalid argument
    The device /dev/zero is so small that it cannot possibly store a file system or partition table.  Perhaps you selected the wrong device?
    Error fsyncing/closing /dev/zero: Invalid argument
    Backtrace has 10 calls on stack:
    ...
    [Same as above]

Bisected the cause to this commit from 2015-03-09 in GParted 0.22.0.  It
claimed to make no functional change.  That turned out not to be true.
    51ac4d5648
    Split get_device_and_disk() into two (#743181)

Fix by simply adding the missed if condition in get_device().

Bug 756434 - GParted dumps core when passing non-existent or invalid
             device on the command line
This commit is contained in:
Mike Fleetwood 2015-10-12 14:33:14 +01:00 committed by Curtis Gedak
parent 23b5ba4e4e
commit 663807802f
1 changed files with 1 additions and 0 deletions

View File

@ -3930,6 +3930,7 @@ bool GParted_Core::flush_device( PedDevice * lp_device )
bool GParted_Core::get_device( const Glib::ustring & device_path, PedDevice *& lp_device, bool flush )
{
lp_device = ped_device_get( device_path.c_str() );
if ( lp_device )
{
if ( flush )
// Force cache coherency before going on to read the partition