1
0
Fork 0

Avoid crashing when udev_device_get_parent() returns a NULL pointer

This commit is contained in:
Ganael Laplanche 2019-05-29 12:06:07 +02:00
parent db8985fc76
commit 66e6afb449

View file

@ -481,14 +481,16 @@ void FGLinuxEventInput::postinit()
struct udev_device *dev = udev_device_new_from_syspath(udev, path); struct udev_device *dev = udev_device_new_from_syspath(udev, path);
const char * node = udev_device_get_devnode(dev); const char * node = udev_device_get_devnode(dev);
dev = udev_device_get_parent( dev ); struct udev_device * parent_dev = udev_device_get_parent( dev );
const char * name = udev_device_get_sysattr_value(dev,"name"); if ( parent_dev != NULL ) {
const char * serial = udev_device_get_sysattr_value(dev, "serial"); const char * name = udev_device_get_sysattr_value(parent_dev,"name");
const char * serial = udev_device_get_sysattr_value(parent_dev, "serial");
SG_LOG(SG_INPUT,SG_DEBUG, "name=" << (name?name:"<null>") << ", node=" << (node?node:"<null>")); SG_LOG(SG_INPUT,SG_DEBUG, "name=" << (name?name:"<null>") << ", node=" << (node?node:"<null>"));
if( name && node ) { if( name && node ) {
std::string serialString = serial ? serial : std::string{}; std::string serialString = serial ? serial : std::string{};
AddDevice( new FGLinuxInputDevice(name, node, serialString) ); AddDevice( new FGLinuxInputDevice(name, node, serialString) );
} }
}
udev_device_unref(dev); udev_device_unref(dev);
} }