summaryrefslogtreecommitdiffstats
path: root/sys/boot/i386/boot2
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2012-03-05 19:53:17 +0000
committerjhb <jhb@FreeBSD.org>2012-03-05 19:53:17 +0000
commit288d581e559a0492fb49ed16c365b11afd84c584 (patch)
tree95bb46daa217498272f153e99164e3e282f4291d /sys/boot/i386/boot2
parentb9d94deee6e0628df1537abc79161c7b0680ba54 (diff)
downloadFreeBSD-src-288d581e559a0492fb49ed16c365b11afd84c584.zip
FreeBSD-src-288d581e559a0492fb49ed16c365b11afd84c584.tar.gz
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. Tested by: Domagoj Smolcic rank1seeker of gmail MFC after: 1 week
Diffstat (limited to 'sys/boot/i386/boot2')
-rw-r--r--sys/boot/i386/boot2/boot2.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/sys/boot/i386/boot2/boot2.c b/sys/boot/i386/boot2/boot2.c
index 3603924..8291249 100644
--- a/sys/boot/i386/boot2/boot2.c
+++ b/sys/boot/i386/boot2/boot2.c
@@ -128,7 +128,7 @@ static struct dsk {
unsigned start;
int init;
} dsk;
-static char cmd[512], cmddup[512];
+static char cmd[512], cmddup[512], knamebuf[1024];
static const char *kname;
static uint32_t opts;
static int comspeed = SIOSPD;
@@ -223,7 +223,9 @@ main(void)
{
uint8_t autoboot;
ino_t ino;
+ size_t nbyte;
+ opts = 0;
kname = NULL;
dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base);
v86.ctl = V86_FLAGS;
@@ -240,8 +242,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 +262,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 +461,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;
}
OpenPOWER on IntegriCloud