Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Mar 2012 17:22:43 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r233374 - stable/9/sys/boot/i386/boot2
Message-ID:  <201203231722.q2NHMh5D086207@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Fri Mar 23 17:22:43 2012
New Revision: 233374
URL: http://svn.freebsd.org/changeset/base/233374

Log:
  MFC 232570,232754:
  Fix boot2 to handle boot config files that only contain a custom path to
  a loader or kernel.  Specifically, kname cannot be pointed at cmd[] since
  it's value is change to be an empty string after the initial call to
  parse, and cmd[]'s value can be changed (thus losing a prior setting for
  kname) due to user input at the boot prompt.  While here, ensure that that
  initial boot config file text is nul-terminated, that ops is initialized
  to zero, and that kname is always initialized to a valid string.
  
  In addition, include other changes to ensure boot2 still builds with
  Clang.

Modified:
  stable/9/sys/boot/i386/boot2/boot2.c

Modified: stable/9/sys/boot/i386/boot2/boot2.c
==============================================================================
--- stable/9/sys/boot/i386/boot2/boot2.c	Fri Mar 23 17:11:36 2012	(r233373)
+++ stable/9/sys/boot/i386/boot2/boot2.c	Fri Mar 23 17:22:43 2012	(r233374)
@@ -128,9 +128,9 @@ static struct dsk {
     unsigned start;
     int init;
 } dsk;
-static char cmd[512], cmddup[512];
-static const char *kname;
-static uint32_t opts;
+static char cmd[512], cmddup[512], knamebuf[1024];
+static const char *kname = NULL;
+static uint32_t opts = 0;
 static int comspeed = SIOSPD;
 static struct bootinfo bootinfo;
 static uint8_t ioctrl = IO_KEYBOARD;
@@ -223,8 +223,8 @@ main(void)
 {
     uint8_t autoboot;
     ino_t ino;
+    size_t nbyte;
 
-    kname = NULL;
     dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base);
     v86.ctl = V86_FLAGS;
     v86.efl = PSL_RESERVED_DEFAULT | PSL_I;
@@ -240,8 +240,10 @@ main(void)
     autoboot = 1;
 
     if ((ino = lookup(PATH_CONFIG)) ||
-        (ino = lookup(PATH_DOTCONFIG)))
-	fsread(ino, cmd, sizeof(cmd));
+        (ino = lookup(PATH_DOTCONFIG))) {
+	nbyte = fsread(ino, cmd, sizeof(cmd) - 1);
+	cmd[nbyte] = '\0';
+    }
 
     if (*cmd) {
 	memcpy(cmddup, cmd, sizeof(cmd));
@@ -258,9 +260,9 @@ main(void)
      * or in case of failure, try to load a kernel directly instead.
      */
 
-    if (autoboot && !kname) {
+    if (!kname) {
 	kname = PATH_BOOT3;
-	if (!keyhit(3*SECOND)) {
+	if (autoboot && !keyhit(3*SECOND)) {
 	    load();
 	    kname = PATH_KERNEL;
 	}
@@ -457,7 +459,12 @@ parse()
 			     ? DRV_HARD : 0) + drv;
 		dsk_meta = 0;
 	    }
-            kname = arg;
+	    if ((i = ep - arg)) {
+		if ((size_t)i >= sizeof(knamebuf))
+		    return -1;
+		memcpy(knamebuf, arg, i + 1);
+		kname = knamebuf;
+	    }
 	}
 	arg = p;
     }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203231722.q2NHMh5D086207>