Avoid a kio-mtp crash when trying to add a blocked device to the device cache
ClosedPublic

Authored by jtamate on Jul 16 2018, 12:14 PM.

Details

Summary

When the device is blocked, for example by amarok mtp plugin, the result of LIBMTP_Open_Raw_Device_Uncached(rawDevice) is nullptr and
LIBMTP_Get_Friendlyname(nullptr) crashes.

Avoid to create a cache for a device that can't be opened.

CCBUG: 396527

Test Plan

With Amarok started and its mtp plugin enabled, plug in an android device.
Try to open it with dolphin, always the same kio backtrace:

==13233== Invalid read of size 8
==13233==    at 0x1087ABCE: LIBMTP_Get_Friendlyname (in /usr/lib64/libmtp.so.9.4.0)
==13233==    by 0x105EE67C: CachedDevice::CachedDevice(LIBMTP_mtpdevice_struct*, LIBMTP_raw_device_struct*, QString, int) (devicecache.cpp:44)
==13233==    by 0x105F0A30: DeviceCache::checkDevice(Solid::Device) (devicecache.cpp:150)
==13233==    by 0x105F1517: DeviceCache::DeviceCache(int, QObject*) (devicecache.cpp:94)
==13233==    by 0x105F2FC1: MTPSlave::MTPSlave(QByteArray const&, QByteArray const&) (kio_mtp.cpp:70)
==13233==    by 0x105F8BF9: kdemain (kio_mtp.cpp:54)
==13233==    by 0x4016CC: main (kioslave.cpp:130)
==13233==  Address 0x8 is not stack'd, malloc'd or (recently) free'd

And in dolphin, the message: MTP died unexpectedly

After, the message: The file or folder udi=/org/kde/solid/udev/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1 does not exist.

Diff Detail

Repository
R320 KIO Extras
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
jtamate requested review of this revision.Jul 16 2018, 12:14 PM
jtamate created this revision.

Should this show an error to the user? I could also imagine this interfering with thumbnail generation when viewing the device

elvisangelaccio accepted this revision.Jul 21 2018, 9:24 AM
This revision is now accepted and ready to land.Jul 21 2018, 9:24 AM
This revision was automatically updated to reflect the committed changes.