-
assigned issue to
- changed milestone to 1.1 RC
Spring.Utils|TEnvironment.SetEnvironmentVariable documentation mismatch and possible AV
In order to remove an environment variable, you have to pass a NULL pointer to the WinApi/SetEnvironmentVariable [1] function. TEnvironment.SetEnvironmentVariable expects a string. That string is casted to a PChar. Even if the given string is empty, the PChar it is casted to will never be a NULL pointer. This way the environment variables cannot be removed with Spring, only set to an empty string. So the documentation is wrong when it states variables can be removed.
Furthermore, when reading out an environment variable that is an empty string (a PChar to a #0 character), the inner function GetProcessEnvironmentVariable will trigger an AV because it is calling
SetLength(Result, 0)
followed by
Windows.GetEnvironmentVariable(PChar(variable), PChar(Result), len);
Attached is a minimal example. Please note that I only used the method overloads for using TEnvironmentVariableTarget.evtProcess. evtUser and evtMachine were not tested.
[1] http://msdn.microsoft.com/en-us/library/windows/desktop/ms686206(v=vs.85).aspx
Comments (6)
-
repo owner -
repo owner - changed status to resolved
fixed issue
#40and some code cleanup→ <<cset f4d4e470c60a>>
-
repo owner - changed milestone to 1.1
-
repo owner - changed version to 1.0 (released)
-
repo owner - changed version to 1.0 (master)
-
repo owner - changed version to 1.0
- Log in to comment
Thanks for your report. I will look into it and fix it for the next version which will be released later this year.