From 3dafa54e8bf4c2ed74be4b736e7a4330b5463da8 Mon Sep 17 00:00:00 2001 From: "C. Masloch" Date: Wed, 30 Aug 2023 10:57:24 +0200 Subject: [PATCH] config: delete existing variable before writing new contents --- kernel/asmsupt.asm | 2 -- kernel/config.c | 26 ++++++++++++++++++++++++++ kernel/kernel.ld | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/kernel/asmsupt.asm b/kernel/asmsupt.asm index 82bb69f..d91f0a0 100644 --- a/kernel/asmsupt.asm +++ b/kernel/asmsupt.asm @@ -327,7 +327,6 @@ strcpy_loop: jmp short pascal_return ;****************************************************************** -%ifndef _INIT global FSTRLEN FSTRLEN: call pascal_setup @@ -337,7 +336,6 @@ FSTRLEN: mov bl,4 jmp short dostrlen -%endif ;********************************************** global STRLEN diff --git a/kernel/config.c b/kernel/config.c index 765c33e..d84528f 100644 --- a/kernel/config.c +++ b/kernel/config.c @@ -2739,6 +2739,30 @@ VOID DoInstall(void) return; } +STATIC BYTE far * searchvar(const BYTE * name, int length) +{ + BYTE far * pp = master_env; + do { + if (!fmemcmp(name, pp, length + 1)) { + return pp; + } + pp += fstrlen(pp) + 1; + } while (*pp); + return NULL; +} + +STATIC void deletevar(const BYTE * name, int length) { + int variablelength; + BYTE far * pp = searchvar(name, length); + if (NULL == pp) + return; + variablelength = fstrlen(pp) + 1; + fmemcpy(pp, pp + variablelength, envp + 3 - (pp + variablelength)); + /* our fmemcpy always copies forwards */ + envp -= variablelength; + return; +} + STATIC VOID CmdSet(BYTE *pLine) { pLine = GetStringArg(pLine, szBuf); @@ -2747,7 +2771,9 @@ STATIC VOID CmdSet(BYTE *pLine) { int size; strupr(szBuf); /* all environment variables must be uppercase */ + size = strlen(szBuf); strcat(szBuf, "="); + deletevar(szBuf, size); pLine = skipwh(++pLine); strcat(szBuf, pLine); /* append the variable value (may include spaces) */ size = strlen(szBuf); diff --git a/kernel/kernel.ld b/kernel/kernel.ld index e65b098..7b45b43 100755 --- a/kernel/kernel.ld +++ b/kernel/kernel.ld @@ -150,6 +150,7 @@ SECTIONS _init_strcpy = INIT_STRCPY; _init_fstrcpy = INIT_FSTRCPY; _init_strlen = INIT_STRLEN; + _init_fstrlen = INIT_FSTRLEN; _init_strchr = INIT_STRCHR; _UMB_get_largest = UMB_GET_LARGEST; _init_call_intr = INIT_CALL_INTR;