usb-host: Filter out abnormal devpath 71/300771/1 accepted/tizen/unified/20231107.172852
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 04:32:58 +0000 (13:32 +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: Ib1fec597f632ce705706be05cd1f233226a0de32
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/usb-host/usb-host.c

index 7ef0a1b07ba6a14883977051aadcee07f4512664..3016504eb3c330196ab7aee73354acdb0039a9aa 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>
@@ -194,6 +195,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) {
@@ -331,7 +335,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;
        }
@@ -412,7 +416,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;
                }
@@ -750,7 +754,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;