config: make sure word marker trailing in environment is zero

This commit is contained in:
C. Masloch 2023-07-03 11:25:33 +02:00 committed by Kenneth J Davis
parent 3d1ba0d486
commit a0549a395e
2 changed files with 8 additions and 2 deletions

View File

@ -2423,6 +2423,8 @@ RestartInput:
fstrcpy(envp, buffer);
envp += len + 1;
*envp = 0;
envp[1] = 0;
envp[2] = 0;
}
if (MenuColor != -1)
ClearScreen(0x7);
@ -2749,11 +2751,15 @@ STATIC VOID CmdSet(BYTE *pLine)
pLine = skipwh(++pLine);
strcat(szBuf, pLine); /* append the variable value (may include spaces) */
size = strlen(szBuf);
if (size < master_env + sizeof(master_env) - envp - 1)
if (size < master_env + sizeof(master_env) - envp - 1 - 2)
{ /* must end with two consequtive zeros */
fstrcpy(envp, szBuf);
envp += size + 1; /* add next variables starting at the second zero */
*envp = 0;
envp[1] = 0;
envp[2] = 0;
/* The word marker after last variable should not equal 1,
to indicate that there is no executable pathname following. */
}
else
printf("Master environment is full - can't add \"%s\"\n", szBuf);

View File

@ -466,7 +466,7 @@ STATIC void kernel()
CommandTail Cmd;
if (master_env[0] == '\0') /* some shells panic on empty master env. */
fmemcpy(master_env, "PATH=.\0\0", sizeof("PATH=.\0\0"));
fmemcpy(master_env, "PATH=.\0\0\0\0", sizeof("PATH=.\0\0\0\0"));
/* process 0 */
/* Execute command.com from the drive we just booted from */