You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(Core): Environment used ANSI Win32 calls, and wrote a store it did not read
Two Windows defects, found while triaging a CNA test that could not see a
variable it had just set.
THE TWO STORES. SetEnvironmentVariable writes the Win32 process environment
block. getenv/_dupenv_s -- which is what this file's own
tryGetEnvironmentVariable reads, and what CNA's getenv callers read -- reads the
CRT's copy, which the Win32 call does not touch. So on Windows a variable set
through Environment::SetEnvironmentVariable was invisible to
Environment::GetEnvironmentVariable, in the same process. _wputenv_s updates
both and is now the normal route.
The present-but-empty case still goes through the wide Win32 call alone, because
_wputenv_s deletes on an empty value and cannot express it. It is then visible
to a Win32 read and not to a CRT read -- a limitation of the CRT environment,
recorded in the comment rather than papered over.
THE ANSI CALLS. Nine Win32 entry points here were the ...A twins, which
substitute '?' for anything the process code page cannot spell. Every one of
them returns a path or a name:
GetCurrentDirectoryA / SetCurrentDirectoryA the working directory
GetModuleFileNameA the executable's own path
SHGetFolderPathA every special folder
GetComputerNameA the machine name
GetUserNameA the user's own account name
SetEnvironmentVariableA names and values
The last is the case that motivated this: a user whose Windows account name is
not representable in the code page had that name destroyed before any caller
could do anything about it, and every special folder underneath it with it. All
now use the wide entry point and convert explicitly through CP_UTF8, which is
the encoding the narrow std::string API here means.
GetLogicalDriveStringsA is deliberately left: drive letters are ASCII by
construction.
Linux: 127/127 Environment tests pass. The changed code is inside
`#if defined(_WIN32)`, so Linux behaviour is untouched by construction.
0 commit comments