Date: Fri, 23 Mar 2012 17:24:52 +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-8@freebsd.org Subject: svn commit: r233377 - in stable/8/sys: boot/i386/boot2 i386/conf Message-ID: <201203231724.q2NHOqS9086394@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb Date: Fri Mar 23 17:24:52 2012 New Revision: 233377 URL: http://svn.freebsd.org/changeset/base/233377 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/8/sys/boot/i386/boot2/boot2.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/boot/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/e1000/ (props changed) stable/8/sys/i386/conf/XENHVM (props changed) Modified: stable/8/sys/boot/i386/boot2/boot2.c ============================================================================== --- stable/8/sys/boot/i386/boot2/boot2.c Fri Mar 23 17:24:29 2012 (r233376) +++ stable/8/sys/boot/i386/boot2/boot2.c Fri Mar 23 17:24:52 2012 (r233377) @@ -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?201203231724.q2NHOqS9086394>