Module Name:    src
Committed By:   thorpej
Date:           Sat May 22 15:04:34 UTC 2021

Modified Files:
        src/sys/arch/alpha/alpha: autoconf.c

Log Message:
qemu_find_rootdev(): Zero the buffer that we use to fetch the Qemu
"prom" root device variable; junk past the trailing NUL would cause
the way we parse the string to fail.  Also parse rootdev= and root=
the same way ("be liberal in what you accept" approach).


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/alpha/alpha/autoconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/alpha/alpha/autoconf.c
diff -u src/sys/arch/alpha/alpha/autoconf.c:1.55 src/sys/arch/alpha/alpha/autoconf.c:1.56
--- src/sys/arch/alpha/alpha/autoconf.c:1.55	Sat Oct  3 17:31:46 2020
+++ src/sys/arch/alpha/alpha/autoconf.c	Sat May 22 15:04:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: autoconf.c,v 1.55 2020/10/03 17:31:46 thorpej Exp $ */
+/* $NetBSD: autoconf.c,v 1.56 2021/05/22 15:04:33 thorpej Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -42,7 +42,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.55 2020/10/03 17:31:46 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.56 2021/05/22 15:04:33 thorpej Exp $");
 
 #include "pci.h"
 
@@ -100,11 +100,22 @@ cpu_configure(void)
 static void
 qemu_find_rootdev(void)
 {
-	char buf[32];
+	char buf[32] = { 0 };
 
 	/*
 	 * Check for "rootdev=wd0".
 	 */
+	if (! prom_qemu_getenv("rootdev", buf, sizeof(buf))) {
+		/*
+		 * Check "root=/dev/wd0a", "root=/dev/hda1", etc.
+		 */
+		if (! prom_qemu_getenv("root", buf, sizeof(buf))) {
+			printf("WARNING: no rootdev= or root= arguments "
+			       "provided by Qemu\n");
+			return;
+		}
+	}
+
 	if (prom_qemu_getenv("rootdev", buf, sizeof(buf))) {
 		snprintf(bootinfo.booted_dev, sizeof(bootinfo.booted_dev),
 		    "rootdev=%s", buf);
@@ -112,35 +123,26 @@ qemu_find_rootdev(void)
 		return;
 	}
 
-	/*
-	 * Check for "root=/dev/wd0a", "root=/dev/hda1", etc.
-	 */
-	if (prom_qemu_getenv("root", buf, sizeof(buf))) {
-		const size_t devlen = strlen("/dev/");
-		const char *cp = buf;
-		char *ecp = &buf[sizeof(buf) - 1];
-
-		snprintf(bootinfo.booted_dev, sizeof(bootinfo.booted_dev),
-		    "root=%s", buf);
-
-		/* Find the start of the device xname. */
-		if (strlen(cp) > devlen && strncmp(cp, "/dev/", devlen) == 0) {
-			cp += devlen;
-		}
+	const size_t devlen = strlen("/dev/");
+	const char *cp = buf;
+	char *ecp = &buf[sizeof(buf) - 1];
+
+	/* Find the start of the device xname. */
+	if (strlen(cp) > devlen && strncmp(cp, "/dev/", devlen) == 0) {
+		cp += devlen;
+	}
 
-		/* Now strip any partition letter off the end. */
-		while (ecp != cp) {
-			if (*ecp >= '0' && *ecp <= '9') {
-				break;
-			}
-			*ecp-- = '\0';
+	/* Now strip any partition letter off the end. */
+	while (ecp != cp) {
+		if (*ecp >= '0' && *ecp <= '9') {
+			break;
 		}
-
-		booted_device = device_find_by_xname(cp);
-		return;
+		*ecp-- = '\0';
 	}
 
-	printf("WARNING: no rootdev= or root= arguments provided by Qemu\n");
+	snprintf(bootinfo.booted_dev, sizeof(bootinfo.booted_dev),
+	    "root=%s", cp);
+	booted_device = device_find_by_xname(cp);
 }
 
 void

Reply via email to