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
This commit is contained in:
ian 2019-02-20 03:00:55 +00:00
parent 8c28d663d3
commit 9ac51119a8

View File

@ -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. */