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
This commit is contained in:
parent
281a359e83
commit
ea6ed0ba9f
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user