mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 01:15:09 +00:00
[KERNEL32]
- Make sure GetEnvironmentVariableW does not use uninitialized variable - Fix GetDllLoadPath not terminating string with NULL if PATH env variable is not defined. Fixes hang on manual INF selection in New Device wizard. See issue #6480 for more details. svn path=/trunk/; revision=54406
This commit is contained in:
parent
5d3b2bfa7c
commit
73a27600f4
2 changed files with 38 additions and 15 deletions
|
@ -182,11 +182,10 @@ GetEnvironmentVariableW(IN LPCWSTR lpName,
|
||||||
UniSize = UNICODE_STRING_MAX_BYTES - sizeof(UNICODE_NULL);
|
UniSize = UNICODE_STRING_MAX_BYTES - sizeof(UNICODE_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RtlInitEmptyUnicodeString(&VarValue, lpBuffer, UniSize);
|
||||||
Status = RtlInitUnicodeStringEx(&VarName, lpName);
|
Status = RtlInitUnicodeStringEx(&VarName, lpName);
|
||||||
if (NT_SUCCESS(Status))
|
if (NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
RtlInitEmptyUnicodeString(&VarValue, lpBuffer, UniSize);
|
|
||||||
|
|
||||||
Status = RtlQueryEnvironmentVariable_U(NULL, &VarName, &VarValue);
|
Status = RtlQueryEnvironmentVariable_U(NULL, &VarName, &VarValue);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
|
|
@ -80,7 +80,7 @@ BasepMapModuleHandle(HMODULE hModule, BOOLEAN AsDataFile)
|
||||||
LPWSTR
|
LPWSTR
|
||||||
GetDllLoadPath(LPCWSTR lpModule)
|
GetDllLoadPath(LPCWSTR lpModule)
|
||||||
{
|
{
|
||||||
ULONG Pos = 0, Length = 0;
|
ULONG Pos = 0, Length = 4, Tmp;
|
||||||
PWCHAR EnvironmentBufferW = NULL;
|
PWCHAR EnvironmentBufferW = NULL;
|
||||||
LPCWSTR lpModuleEnd = NULL;
|
LPCWSTR lpModuleEnd = NULL;
|
||||||
UNICODE_STRING ModuleName;
|
UNICODE_STRING ModuleName;
|
||||||
|
@ -88,7 +88,7 @@ GetDllLoadPath(LPCWSTR lpModule)
|
||||||
|
|
||||||
// FIXME: This function is used only by SearchPathW, and is deprecated and will be deleted ASAP.
|
// FIXME: This function is used only by SearchPathW, and is deprecated and will be deleted ASAP.
|
||||||
|
|
||||||
if ((lpModule != NULL) && (wcslen(lpModule) > 2) && (lpModule[1] == ':'))
|
if (lpModule != NULL && wcslen(lpModule) > 2 && lpModule[1] == ':')
|
||||||
{
|
{
|
||||||
lpModuleEnd = lpModule + wcslen(lpModule);
|
lpModuleEnd = lpModule + wcslen(lpModule);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ GetDllLoadPath(LPCWSTR lpModule)
|
||||||
Length += GetEnvironmentVariableW(L"PATH", NULL, 0);
|
Length += GetEnvironmentVariableW(L"PATH", NULL, 0);
|
||||||
|
|
||||||
EnvironmentBufferW = RtlAllocateHeap(RtlGetProcessHeap(), 0,
|
EnvironmentBufferW = RtlAllocateHeap(RtlGetProcessHeap(), 0,
|
||||||
Length * sizeof(WCHAR));
|
(Length + 1) * sizeof(WCHAR));
|
||||||
if (EnvironmentBufferW == NULL)
|
if (EnvironmentBufferW == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -130,15 +130,39 @@ GetDllLoadPath(LPCWSTR lpModule)
|
||||||
EnvironmentBufferW[Pos++] = L';';
|
EnvironmentBufferW[Pos++] = L';';
|
||||||
}
|
}
|
||||||
|
|
||||||
Pos += GetCurrentDirectoryW(Length, EnvironmentBufferW + Pos);
|
Tmp = GetCurrentDirectoryW(Length, EnvironmentBufferW + Pos);
|
||||||
EnvironmentBufferW[Pos++] = L';';
|
if(Tmp > 0 && Tmp < Length - Pos)
|
||||||
Pos += GetDllDirectoryW(Length - Pos, EnvironmentBufferW + Pos);
|
{
|
||||||
EnvironmentBufferW[Pos++] = L';';
|
Pos += Tmp;
|
||||||
Pos += GetSystemDirectoryW(EnvironmentBufferW + Pos, Length - Pos);
|
if(Pos < Length) EnvironmentBufferW[Pos++] = L';';
|
||||||
EnvironmentBufferW[Pos++] = L';';
|
}
|
||||||
Pos += GetWindowsDirectoryW(EnvironmentBufferW + Pos, Length - Pos);
|
|
||||||
EnvironmentBufferW[Pos++] = L';';
|
Tmp = GetDllDirectoryW(Length - Pos, EnvironmentBufferW + Pos);
|
||||||
Pos += GetEnvironmentVariableW(L"PATH", EnvironmentBufferW + Pos, Length - Pos);
|
if(Tmp > 0 && Tmp < Length - Pos)
|
||||||
|
{
|
||||||
|
Pos += Tmp;
|
||||||
|
if(Pos < Length) EnvironmentBufferW[Pos++] = L';';
|
||||||
|
}
|
||||||
|
|
||||||
|
Tmp = GetSystemDirectoryW(EnvironmentBufferW + Pos, Length - Pos);
|
||||||
|
if(Tmp > 0 && Tmp < Length - Pos)
|
||||||
|
{
|
||||||
|
Pos += Tmp;
|
||||||
|
if(Pos < Length) EnvironmentBufferW[Pos++] = L';';
|
||||||
|
}
|
||||||
|
|
||||||
|
Tmp = GetWindowsDirectoryW(EnvironmentBufferW + Pos, Length - Pos);
|
||||||
|
if(Tmp > 0 && Tmp < Length - Pos)
|
||||||
|
{
|
||||||
|
Pos += Tmp;
|
||||||
|
if(Pos < Length) EnvironmentBufferW[Pos++] = L';';
|
||||||
|
}
|
||||||
|
|
||||||
|
Tmp = GetEnvironmentVariableW(L"PATH", EnvironmentBufferW + Pos, Length - Pos);
|
||||||
|
|
||||||
|
/* Make sure buffer is null terminated */
|
||||||
|
EnvironmentBufferW[Pos++] = UNICODE_NULL;
|
||||||
|
|
||||||
|
|
||||||
SetLastError(LastError);
|
SetLastError(LastError);
|
||||||
return EnvironmentBufferW;
|
return EnvironmentBufferW;
|
||||||
|
|
Loading…
Reference in a new issue