From 9ac51119a850e55642656a77e74a98649424d172 Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 20 Feb 2019 03:00:55 +0000 Subject: [PATCH] Fix the handling of legacy-format devices in the u-boot loaderdev variable. When I added support for the standard loader(8) disk0s2a: type formats, the parsing of legacy format was broken because it also contains a colon, but it comes before the slice and partition. That would cause disk_parsedev() to return success with the slice and partition set to wildcard values. This change examines the string first, and if it contains spaces, dots, or a colon at any position other than the end, it must be a legacy-format string and we don't even try to use disk_parsedev() on it. Reported by: Manuel Stuhn --- stand/uboot/common/main.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/stand/uboot/common/main.c b/stand/uboot/common/main.c index d420aa95a59..df53097c2a7 100644 --- a/stand/uboot/common/main.c +++ b/stand/uboot/common/main.c @@ -226,16 +226,23 @@ get_load_device(int *type, int *unit, int *slice, int *partition) p = get_device_type(devstr, type); /* - * If type is DEV_TYP_STOR we have a disk-like device. If we can parse - * the remainder of the string as a standard unit+slice+partition (e.g., - * 0s2a or 1p12), return those results. Otherwise we'll fall through to - * the code that parses the legacy format. + * If type is DEV_TYP_STOR we have a disk-like device. If the remainder + * of the string contains spaces, dots, or a colon in any location other + * than the last char, it's legacy format. Otherwise it might be + * standard loader(8) format (e.g., disk0s2a or mmc1p12), so try to + * parse the remainder of the string as such, and if it works, return + * those results. Otherwise we'll fall through to the code that parses + * the legacy format. */ - if ((*type & DEV_TYP_STOR) && disk_parsedev(&dev, p, NULL) == 0) { - *unit = dev.dd.d_unit; - *slice = dev.d_slice; - *partition = dev.d_partition; - return; + if (*type & DEV_TYP_STOR) { + size_t len = strlen(p); + if (strcspn(p, " .") == len && strcspn(p, ":") >= len - 1 && + disk_parsedev(&dev, p, NULL) == 0) { + *unit = dev.dd.d_unit; + *slice = dev.d_slice; + *partition = dev.d_partition; + return; + } } /* Ignore optional spaces after the device name. */ -- 2.45.0