OSDN Git Service

input/hog: Fix crash if uhid is not enabled
authorSzymon Janc <szymon.janc@codecoup.pl>
Fri, 1 Apr 2016 19:58:29 +0000 (21:58 +0200)
committerJohan Hedberg <johan.hedberg@intel.com>
Sat, 2 Apr 2016 07:47:35 +0000 (10:47 +0300)
If /dev/uhid is not present bt_hog_new_default() returns NULL.
This was resulting in NULL pointer dereference in attio_connected_cb.

profiles/input/hog.c

index 4dba83f..a934c62 100644 (file)
@@ -107,8 +107,13 @@ static struct hog_device *hog_device_new(struct btd_device *device,
                                                        product, version);
 
        dev = new0(struct hog_device, 1);
-       dev->device = btd_device_ref(device);
        dev->hog = bt_hog_new_default(name, vendor, product, version, prim);
+       if (!dev->hog) {
+               free(dev);
+               return NULL;
+       }
+
+       dev->device = btd_device_ref(device);
 
        /*
         * TODO: Remove attio callback and use .accept once using
@@ -189,6 +194,9 @@ static int hog_probe(struct btd_service *service)
                        continue;
 
                dev = hog_device_new(device, prim);
+               if (!dev)
+                       break;
+
                btd_service_set_user_data(service, dev);
                return 0;
        }