Author: ian
Date: Wed Feb 20 03:00:55 2019
New Revision: 344335
URL: https://svnweb.freebsd.org/changeset/base/344335

Log:
  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

Modified:
  head/stand/uboot/common/main.c

Modified: head/stand/uboot/common/main.c
==============================================================================
--- head/stand/uboot/common/main.c      Wed Feb 20 02:49:26 2019        
(r344334)
+++ head/stand/uboot/common/main.c      Wed Feb 20 03:00:55 2019        
(r344335)
@@ -226,16 +226,23 @@ get_load_device(int *type, int *unit, int *slice, int 
        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. */
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to