[2/2] discover/platform-powerpc: Reject bootdevs with empty UUIDs
diff mbox

Message ID 20161122015321.24126-2-sam@mendozajonas.com
State Accepted
Headers show

Commit Message

Samuel Mendoza-Jonas Nov. 22, 2016, 1:53 a.m. UTC
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 | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Patch
diff mbox

diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c
index af28f85..3efc1b9 100644
--- a/discover/platform-powerpc.c
+++ b/discover/platform-powerpc.c
@@ -411,11 +411,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) {
@@ -429,9 +427,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 */