From cf3fabacaa141a1224a2ad239806a1fa28b51687 Mon Sep 17 00:00:00 2001 From: Long Li Date: Wed, 21 Mar 2018 03:51:28 -0700 Subject: [PATCH] v3: Properly parsing SCSI Hyperv devices (#8509) 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 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index 9ce2079..0a32363 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -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); } -- 2.7.4