block: Check return value of udev_device_get_syspath() 37/297937/1 accepted/tizen/8.0/unified/20231005.093850 accepted/tizen/unified/20230915.085351 accepted/tizen/unified/20230915.160548 tizen_8.0_m2_release
authorUnsung Lee <unsung.lee@samsung.com>
Tue, 29 Aug 2023 02:33:50 +0000 (11:33 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 29 Aug 2023 02:41:54 +0000 (11:41 +0900)
Check return value of udev_device_get_syspath() to avoid
passing NULL parameter in rindex() function.

This solves bug reported by SVACE with WGID 540346.

Change-Id: Ic795e66c7b220ab1c5ced33901c86befb1e6f7db
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/block/block.c

index 6e72ab6..e70f462 100644 (file)
@@ -2193,9 +2193,14 @@ static int add_block_device(struct udev_device *dev, const char *devnode, bool e
 
        if (extended_internal && !udev_device_get_property_value(dev, "ID_FS_TYPE")) {
                char syspath[128] = {0};
+               const char *path;
                char *r;
 
-               r = rindex(udev_device_get_syspath(dev), '/');
+               path = udev_device_get_syspath(dev);
+               if (!path)
+                       return -ENODEV;
+
+               r = rindex(path, '/');
                if (!r) return -ENODEV;
 
                snprintf(syspath, sizeof(syspath), "/sys/block%s", r);