ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
7e7c9f
From f99cc28e392874b317b4ff2054bbd6970f71ecdd Mon Sep 17 00:00:00 2001
7e7c9f
From: Long Li <longli@microsoft.com>
7e7c9f
Date: Wed, 21 Mar 2018 03:51:28 -0700
7e7c9f
Subject: [PATCH] v3: Properly parsing SCSI Hyperv devices (#8509)
7e7c9f
7e7c9f
Since 2016, Hyperv devices moved to using standard way to expose UUID to sysfs. Fix the parsing function to work with the newer format.
7e7c9f
7e7c9f
Change log:
7e7c9f
v2: changed code to work with both old and new path format
7e7c9f
v3: changed guid_str_len type to size_t, fixed length in char guid[] in handle_scsi_hyperv()
7e7c9f
7e7c9f
(cherry picked from commit cf3fabacaa141a1224a2ad239806a1fa28b51687)
7e7c9f
7e7c9f
Resolves: #1809053
7e7c9f
---
7e7c9f
 src/udev/udev-builtin-path_id.c | 18 ++++++++++++------
7e7c9f
 1 file changed, 12 insertions(+), 6 deletions(-)
7e7c9f
7e7c9f
diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c
7e7c9f
index d113ff21b0..b0bcd80571 100644
7e7c9f
--- a/src/udev/udev-builtin-path_id.c
7e7c9f
+++ b/src/udev/udev-builtin-path_id.c
7e7c9f
@@ -424,14 +424,16 @@ out:
7e7c9f
         return hostdev;
7e7c9f
 }
7e7c9f
 
7e7c9f
-static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char **path) {
7e7c9f
+static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char **path, size_t guid_str_len) {
7e7c9f
         struct udev_device *hostdev;
7e7c9f
         struct udev_device *vmbusdev;
7e7c9f
         const char *guid_str;
7e7c9f
-        char *lun = NULL;
7e7c9f
-        char guid[38];
7e7c9f
+        _cleanup_free_ char *lun = NULL;
7e7c9f
+        char guid[39];
7e7c9f
         size_t i, k;
7e7c9f
 
7e7c9f
+        assert(guid_str_len < sizeof(guid));
7e7c9f
+
7e7c9f
         hostdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
7e7c9f
         if (!hostdev)
7e7c9f
                 return NULL;
7e7c9f
@@ -444,10 +446,10 @@ static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char *
7e7c9f
         if (!guid_str)
7e7c9f
                 return NULL;
7e7c9f
 
7e7c9f
-        if (strlen(guid_str) < 37 || guid_str[0] != '{' || guid_str[36] != '}')
7e7c9f
+        if (strlen(guid_str) < guid_str_len || guid_str[0] != '{' || guid_str[guid_str_len-1] != '}')
7e7c9f
                 return NULL;
7e7c9f
 
7e7c9f
-        for (i = 1, k = 0; i < 36; i++) {
7e7c9f
+        for (i = 1, k = 0; i < guid_str_len-1; i++) {
7e7c9f
                 if (guid_str[i] == '-')
7e7c9f
                         continue;
7e7c9f
                 guid[k++] = guid_str[i];
7e7c9f
@@ -545,7 +547,11 @@ static struct udev_device *handle_scsi(struct udev_device *parent, bool enable_n
7e7c9f
         }
7e7c9f
 
7e7c9f
         if (strstr(name, "/vmbus_") != NULL) {
7e7c9f
-                parent = handle_scsi_hyperv(parent, path);
7e7c9f
+                parent = handle_scsi_hyperv(parent, path, 37);
7e7c9f
+                goto out;
7e7c9f
+        }
7e7c9f
+        else if (strstr(name, "/VMBUS")) {
7e7c9f
+                parent = handle_scsi_hyperv(parent, path, 38);
7e7c9f
                 goto out;
7e7c9f
         }
7e7c9f