Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/alpha/alpha qemu_find_rootdev(): Zero the buffer th...
details: https://anonhg.NetBSD.org/src/rev/33034708e15e
branches: trunk
changeset: 379239:33034708e15e
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sat May 22 15:04:33 2021 +0000
description:
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).
diffstat:
sys/arch/alpha/alpha/autoconf.c | 60 +++++++++++++++++++++-------------------
1 files changed, 31 insertions(+), 29 deletions(-)
diffs (95 lines):
diff -r 6141cf208d50 -r 33034708e15e sys/arch/alpha/alpha/autoconf.c
--- a/sys/arch/alpha/alpha/autoconf.c Sat May 22 13:43:50 2021 +0000
+++ b/sys/arch/alpha/alpha/autoconf.c Sat May 22 15:04:33 2021 +0000
@@ -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);
+ 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';
- }
-
- booted_device = device_find_by_xname(cp);
- return;
+ /* Find the start of the device xname. */
+ if (strlen(cp) > devlen && strncmp(cp, "/dev/", devlen) == 0) {
+ cp += devlen;
}
- printf("WARNING: no rootdev= or root= arguments provided by Qemu\n");
+ /* Now strip any partition letter off the end. */
+ while (ecp != cp) {
+ if (*ecp >= '0' && *ecp <= '9') {
+ break;
+ }
+ *ecp-- = '\0';
+ }
+
+ snprintf(bootinfo.booted_dev, sizeof(bootinfo.booted_dev),
+ "root=%s", cp);
+ booted_device = device_find_by_xname(cp);
}
void
Home |
Main Index |
Thread Index |
Old Index