Properly NUL-terminate the on-stack buffer for reading /boot.config

or /boot/config. In qemu, on a warm boot, the stack is not all zeroes
and we parse beyond the file's contents.

Obtained from:	Juniper Networks, Inc.
This commit is contained in:
Marcel Moolenaar 2014-10-09 01:54:32 +00:00
parent 1e7075e0a4
commit 511037bd43
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=272785

View File

@ -136,6 +136,7 @@ int
main(void)
{
char cmd[512], cmdtmp[512];
ssize_t sz;
int autoboot, dskupdated;
ufs_ino_t ino;
@ -164,9 +165,10 @@ main(void)
for (;;) {
*kname = '\0';
if ((ino = lookup(PATH_CONFIG)) ||
(ino = lookup(PATH_DOTCONFIG)))
fsread(ino, cmd, sizeof(cmd));
(ino = lookup(PATH_DOTCONFIG))) {
sz = fsread(ino, cmd, sizeof(cmd) - 1);
cmd[(sz < 0) ? 0 : sz] = '\0';
}
if (*cmd != '\0') {
memcpy(cmdtmp, cmd, sizeof(cmdtmp));
if (parse(cmdtmp, &dskupdated))