usb-host: Filter out abnormal devpath 68/300768/1 accepted/tizen/7.0/unified/20231102.181239
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 31 Oct 2023 02:21:33 +0000 (11:21 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 2 Nov 2023 03:45:15 +0000 (12:45 +0900)
Sometimes the devpath gets empty string. It is not sure, but the deviced
seems to get blocked in such case, reading the parent's product/serial
node. It leads watchdog timeout, and the deviced gets SIGABRT from the
systemd. It is not clear that the empty devpath results it though, add
guard clauses for filtering out such an abnormal devpath.

 (gdb) bt
 #0  __libc_read (nbytes=4097, buf=0xaba70f28, fd=-1415114968)
     at ../sysdeps/unix/sysv/linux/read.c:26

 #1  __libc_read (fd=fd@entry=28, buf=buf@entry=0xaba70f28,
     nbytes=nbytes@entry=4097) at ../sysdeps/unix/sysv/linux/read.c:24

 #2  0xf76289a2 in read (__nbytes=4097, __buf=0xaba70f28, __fd=28)
     at /usr/include/bits/unistd.h:44

 #3  read_full_virtual_file (filename=<optimized out>, ret_contents=0xffd180ec,
     ret_size=0xffd180f4) at ../src/basic/fileio.c:371

 #4  0xf7626608 in sd_device_get_sysattr_value (device=0xaba084f8,
     sysattr=0xaaefe36c "product", _value=0xffd181b0)
     at ../src/libsystemd/sd-device/sd-device.c:1789

 #5  0xf761c92e in udev_device_get_sysattr_value (
     udev_device=udev_device@entry=0xaba2c060, sysattr=<optimized out>)
     at ../src/libudev/libudev-device.c:741

 #6  0xaaeec55c in add_usbhost_list (dev=dev@entry=0xab9fc4e0,
     devpath=devpath@entry=0xaba3d984 "")
     at /usr/src/debug/deviced-10.0.0-1.arm/src/usb-host/usb-host.c:236

Change-Id: I52ac60e5fefa48ea7e262c3ca7472a019786ca82
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/usb-host/usb-host.c

index 3dc6d78..a9254f4 100644 (file)
@@ -17,6 +17,7 @@
  */
 #include <stdio.h>
 #include <stdint.h>
+#include <string.h>
 #include <limits.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -193,6 +194,9 @@ static int add_usbhost_list(struct udev_device *dev, const char *devpath)
        const char *str;
        struct udev_device *parent;
 
+       if (!devpath || strlen(devpath) == 0)
+               return -EINVAL;
+
        /* allocate new usbhost device */
        usbhost = calloc(1, sizeof(struct usbhost_device));
        if (!usbhost) {
@@ -330,7 +334,7 @@ static void uevent_usbhost_handler(struct udev_device *dev)
 
        /* devpath is an unique information among usb host devices */
        devpath = udev_device_get_devpath(dev);
-       if (!devpath) {
+       if (!devpath || strlen(devpath) == 0) {
                _E("Failed to get devpath from udev_device.");
                return;
        }
@@ -406,7 +410,7 @@ static int usbhost_init_from_udev_enumerate(void)
 
                /* devpath is an unique information among usb host devices */
                devpath = udev_device_get_devpath(dev);
-               if (!devpath) {
+               if (!devpath || strlen(devpath) == 0) {
                        _E("Failed to get devpath from '%s' device.", syspath);
                        continue;
                }
@@ -744,7 +748,7 @@ static int get_device_desc(const char *filepath, struct usb_device_descriptor *d
        }
 
        rdevpath = udev_device_get_devpath(udev_device);
-       if (!rdevpath) {
+       if (!rdevpath || !strlen(rdevpath)) {
                _E("Failed to get devpath from udev_device.");
                ret = -errno;
                goto out;