linux_usbfs: Fix memory allocation failure.
authorGaurav <g.gupta@samsung.com>
Wed, 13 May 2015 07:49:14 +0000 (13:19 +0530)
committerChris Dickens <christopher.a.dickens@gmail.com>
Tue, 19 May 2015 17:29:50 +0000 (10:29 -0700)
strdup returns NULL in case memory allocation failure occurs.
If Null check is not there, it will crash while dereferencing in "strrchr".

Closes #66

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/os/linux_usbfs.c
libusb/version_nano.h

index 0d883bd..86ad1f2 100644 (file)
@@ -997,6 +997,9 @@ static int linux_get_parent_info(struct libusb_device *dev, const char *sysfs_di
        }
 
        parent_sysfs_dir = strdup(sysfs_dir);
+       if (NULL == parent_sysfs_dir) {
+               return LIBUSB_ERROR_NO_MEM;
+       }
        if (NULL != (tmp = strrchr(parent_sysfs_dir, '.')) ||
            NULL != (tmp = strrchr(parent_sysfs_dir, '-'))) {
                dev->port_number = atoi(tmp + 1);
index 3022fb7..3ca816b 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10984
+#define LIBUSB_NANO 10985