mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-09-03 04:13:31 +00:00
[KERNEL32]
Properly fix GetEnvironmentVariableW and set error in case of RtlInitUnicodeStringEx failure svn path=/trunk/; revision=54459
This commit is contained in:
@@ -181,25 +181,29 @@ GetEnvironmentVariableW(IN LPCWSTR lpName,
|
||||
{
|
||||
UniSize = UNICODE_STRING_MAX_BYTES - sizeof(UNICODE_NULL);
|
||||
}
|
||||
|
||||
Status = RtlInitUnicodeStringEx(&VarName, lpName);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
BaseSetLastNTError(Status);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RtlInitEmptyUnicodeString(&VarValue, lpBuffer, UniSize);
|
||||
Status = RtlInitUnicodeStringEx(&VarName, lpName);
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
Status = RtlQueryEnvironmentVariable_U(NULL, &VarName, &VarValue);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
if (Status == STATUS_BUFFER_TOO_SMALL)
|
||||
{
|
||||
return (VarValue.Length / sizeof(WCHAR)) + sizeof(ANSI_NULL);
|
||||
}
|
||||
BaseSetLastNTError (Status);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lpBuffer[VarValue.Length / sizeof(WCHAR)] = UNICODE_NULL;
|
||||
Status = RtlQueryEnvironmentVariable_U(NULL, &VarName, &VarValue);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
if (Status == STATUS_BUFFER_TOO_SMALL)
|
||||
{
|
||||
return (VarValue.Length / sizeof(WCHAR)) + sizeof(ANSI_NULL);
|
||||
}
|
||||
BaseSetLastNTError (Status);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lpBuffer[VarValue.Length / sizeof(WCHAR)] = UNICODE_NULL;
|
||||
|
||||
return (VarValue.Length / sizeof(WCHAR));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user