From 66e6afb449f7c4174c870ed909fa7f5f2abd9f0a Mon Sep 17 00:00:00 2001 From: Ganael Laplanche Date: Wed, 29 May 2019 12:06:07 +0200 Subject: [PATCH] Avoid crashing when udev_device_get_parent() returns a NULL pointer --- src/Input/FGLinuxEventInput.cxx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Input/FGLinuxEventInput.cxx b/src/Input/FGLinuxEventInput.cxx index 6dae43660..db40d9a78 100644 --- a/src/Input/FGLinuxEventInput.cxx +++ b/src/Input/FGLinuxEventInput.cxx @@ -481,13 +481,15 @@ void FGLinuxEventInput::postinit() struct udev_device *dev = udev_device_new_from_syspath(udev, path); const char * node = udev_device_get_devnode(dev); - dev = udev_device_get_parent( dev ); - const char * name = udev_device_get_sysattr_value(dev,"name"); - const char * serial = udev_device_get_sysattr_value(dev, "serial"); - SG_LOG(SG_INPUT,SG_DEBUG, "name=" << (name?name:"") << ", node=" << (node?node:"")); - if( name && node ) { - std::string serialString = serial ? serial : std::string{}; - AddDevice( new FGLinuxInputDevice(name, node, serialString) ); + struct udev_device * parent_dev = udev_device_get_parent( dev ); + if ( parent_dev != NULL ) { + 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:"") << ", node=" << (node?node:"")); + if( name && node ) { + std::string serialString = serial ? serial : std::string{}; + AddDevice( new FGLinuxInputDevice(name, node, serialString) ); + } } udev_device_unref(dev);