mirror of https://github.com/FDOS/kernel.git
config: delete variable only if it makes enough space to write new
This commit is contained in:
parent
6101fb2aed
commit
95694f7e34
|
@ -2768,22 +2768,28 @@ STATIC VOID CmdSet(BYTE *pLine)
|
||||||
pLine = skipwh(pLine); /* scan() stops at the equal sign or space */
|
pLine = skipwh(pLine); /* scan() stops at the equal sign or space */
|
||||||
if (*pLine == '=') /* equal sign is required */
|
if (*pLine == '=') /* equal sign is required */
|
||||||
{
|
{
|
||||||
int size, namesize;
|
int size, oldsize, namesize;
|
||||||
BYTE far * pp;
|
BYTE far * pp;
|
||||||
strupr(szBuf); /* all environment variables must be uppercase */
|
strupr(szBuf); /* all environment variables must be uppercase */
|
||||||
namesize = strlen(szBuf);
|
namesize = strlen(szBuf);
|
||||||
strcat(szBuf, "=");
|
strcat(szBuf, "=");
|
||||||
pp = searchvar(szBuf, namesize);
|
pp = searchvar(szBuf, namesize);
|
||||||
deletevar(pp);
|
|
||||||
pLine = skipwh(++pLine);
|
pLine = skipwh(++pLine);
|
||||||
strcat(szBuf, pLine); /* append the variable value (may include spaces) */
|
strcat(szBuf, pLine); /* append the variable value (may include spaces) */
|
||||||
size = strlen(szBuf);
|
size = strlen(szBuf);
|
||||||
if (size == namesize + 1) {
|
if (size == namesize + 1) {
|
||||||
/* empty variable ? then just delete. */
|
/* empty variable ? then just delete. (cannot fail) */
|
||||||
|
deletevar(pp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (size < master_env + sizeof(master_env) - envp - 1 - 2)
|
if (pp) {
|
||||||
|
oldsize = fstrlen(pp) + 1;
|
||||||
|
} else {
|
||||||
|
oldsize = 0;
|
||||||
|
}
|
||||||
|
if (size < master_env + sizeof(master_env) - (envp - oldsize) - 1 - 2)
|
||||||
{ /* must end with two consequtive zeros */
|
{ /* must end with two consequtive zeros */
|
||||||
|
deletevar(pp); /* now that there's enough space, actually delete */
|
||||||
fstrcpy(envp, szBuf);
|
fstrcpy(envp, szBuf);
|
||||||
envp += size + 1; /* add next variables starting at the second zero */
|
envp += size + 1; /* add next variables starting at the second zero */
|
||||||
*envp = 0;
|
*envp = 0;
|
||||||
|
|
Loading…
Reference in New Issue