diff --git a/reactos/base/shell/cmd/set.c b/reactos/base/shell/cmd/set.c index e04211a27ba..115b837787e 100644 --- a/reactos/base/shell/cmd/set.c +++ b/reactos/base/shell/cmd/set.c @@ -154,7 +154,7 @@ INT cmd_set (LPTSTR param) } *p++ = _T('\0'); - if (!SetEnvironmentVariable(param, p)) + if (!SetEnvironmentVariable(param, *p ? p : NULL)) { nErrorLevel = 1; return 1; diff --git a/reactos/dll/win32/kernel32/misc/env.c b/reactos/dll/win32/kernel32/misc/env.c index b5aa8c5e6cb..c4f0ee25ae8 100644 --- a/reactos/dll/win32/kernel32/misc/env.c +++ b/reactos/dll/win32/kernel32/misc/env.c @@ -193,18 +193,27 @@ SetEnvironmentVariableA ( &VarName, TRUE); - RtlInitAnsiString (&VarValue, - (LPSTR)lpValue); - RtlAnsiStringToUnicodeString (&VarValueU, - &VarValue, - TRUE); + if (lpValue) + { + RtlInitAnsiString (&VarValue, + (LPSTR)lpValue); + RtlAnsiStringToUnicodeString (&VarValueU, + &VarValue, + TRUE); - Status = RtlSetEnvironmentVariable (NULL, - &VarNameU, - &VarValueU); + Status = RtlSetEnvironmentVariable (NULL, + &VarNameU, + &VarValueU); + RtlFreeUnicodeString (&VarValueU); + } + else + { + Status = RtlSetEnvironmentVariable (NULL, + &VarNameU, + NULL); + } RtlFreeUnicodeString (&VarNameU); - RtlFreeUnicodeString (&VarValueU); if (!NT_SUCCESS(Status)) { @@ -235,12 +244,22 @@ SetEnvironmentVariableW ( RtlInitUnicodeString (&VarName, lpName); - RtlInitUnicodeString (&VarValue, - lpValue); + if (lpValue) + { + RtlInitUnicodeString (&VarValue, + lpValue); + + Status = RtlSetEnvironmentVariable (NULL, + &VarName, + &VarValue); + } + else + { + Status = RtlSetEnvironmentVariable (NULL, + &VarName, + NULL); + } - Status = RtlSetEnvironmentVariable (NULL, - &VarName, - &VarValue); if (!NT_SUCCESS(Status)) { SetLastErrorByStatus (Status); diff --git a/reactos/lib/rtl/env.c b/reactos/lib/rtl/env.c index 2e437f71116..86a418ed6c7 100644 --- a/reactos/lib/rtl/env.c +++ b/reactos/lib/rtl/env.c @@ -355,7 +355,7 @@ RtlSetEnvironmentVariable(PWSTR *Environment, } found: - if (Value != NULL && Value->Length > 0) + if (Value != NULL) { hole_len = tail - hole; /* calculate new environment size */