]> git.ozlabs.org Git - petitboot/commitdiff
discover/platform-powerpc: Reject bootdevs with empty UUIDs
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 22 Nov 2016 00:00:42 +0000 (11:00 +1100)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Thu, 24 Nov 2016 00:42:25 +0000 (11:42 +1100)
If a "uuid:" label is set in the petitboot,bootdevs parameter without a
matching UUID, the UUID is unintentionally accepted and set to NULL.
This can cause a segfault in nc-config when device UUIDs are compared
against the autoboot option. Instead treat options like this as
malformed.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/platform-powerpc.c

index 247b4e6d9389956916e63a27fc709d6bb7aa85f7..e5c83a07e1c46039f2fcdf0fca7c3ce778d678a5 100644 (file)
@@ -410,11 +410,9 @@ static int read_bootdev(void *ctx, char **pos, struct autoboot_option *opt)
        if (!strncmp(*pos, "uuid:", strlen("uuid:"))) {
                prefix = strlen("uuid:");
                opt->boot_type = BOOT_DEVICE_UUID;
-               rc = 0;
        } else if (!strncmp(*pos, "mac:", strlen("mac:"))) {
                prefix = strlen("mac:");
                opt->boot_type = BOOT_DEVICE_UUID;
-               rc = 0;
        } else {
                type = find_device_type(*pos);
                if (type != DEVICE_TYPE_UNKNOWN) {
@@ -428,9 +426,12 @@ static int read_bootdev(void *ctx, char **pos, struct autoboot_option *opt)
                if (delim)
                        len = (int)(delim - *pos) - prefix;
                else
-                       len = strlen(*pos);
+                       len = strlen(*pos) - prefix;
 
-               opt->uuid = talloc_strndup(ctx, *pos + prefix, len);
+               if (len) {
+                       opt->uuid = talloc_strndup(ctx, *pos + prefix, len);
+                       rc = 0;
+               }
        }
 
        /* Always advance pointer to next option or end */