v3: Properly parsing SCSI Hyperv devices (#8509)
authorLong Li <longli@microsoft.com>
Wed, 21 Mar 2018 10:51:28 +0000 (03:51 -0700)
committerLennart Poettering <lennart@poettering.net>
Wed, 21 Mar 2018 10:51:28 +0000 (11:51 +0100)
Since 2016, Hyperv devices moved to using standard way to expose UUID to sysfs. Fix the parsing function to work with the newer format.

Change log:
v2: changed code to work with both old and new path format
v3: changed guid_str_len type to size_t, fixed length in char guid[] in handle_scsi_hyperv()

src/udev/udev-builtin-path_id.c

index 9ce2079..0a32363 100644 (file)
@@ -397,16 +397,17 @@ static struct udev_device *handle_scsi_default(struct udev_device *parent, char
         return hostdev;
 }
 
-static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char **path) {
+static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char **path, size_t guid_str_len) {
         struct udev_device *hostdev;
         struct udev_device *vmbusdev;
         const char *guid_str;
         _cleanup_free_ char *lun = NULL;
-        char guid[38];
+        char guid[39];
         size_t i, k;
 
         assert(parent);
         assert(path);
+        assert(guid_str_len < sizeof(guid));
 
         hostdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
         if (!hostdev)
@@ -420,10 +421,10 @@ static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char *
         if (!guid_str)
                 return NULL;
 
-        if (strlen(guid_str) < 37 || guid_str[0] != '{' || guid_str[36] != '}')
+        if (strlen(guid_str) < guid_str_len || guid_str[0] != '{' || guid_str[guid_str_len-1] != '}')
                 return NULL;
 
-        for (i = 1, k = 0; i < 36; i++) {
+        for (i = 1, k = 0; i < guid_str_len-1; i++) {
                 if (guid_str[i] == '-')
                         continue;
                 guid[k++] = guid_str[i];
@@ -472,7 +473,9 @@ static struct udev_device *handle_scsi(struct udev_device *parent, char **path,
                 return handle_scsi_ata(parent, path);
 
         if (strstr(name, "/vmbus_"))
-                return handle_scsi_hyperv(parent, path);
+                return handle_scsi_hyperv(parent, path, 37);
+        else if (strstr(name, "/VMBUS"))
+                return handle_scsi_hyperv(parent, path, 38);
 
         return handle_scsi_default(parent, path);
 }