mirror of
https://github.com/reactos/reactos.git
synced 2025-02-21 16:04:57 +00:00
[0.4.10][DBGHELP] Accept NULL symbol path as reset-to-default CORE-17073 (#3257)
It fixes Heap Corruption when starting KernRate, which I could confirm also in all the older ros branches by using: gflags /p /enable Kernrate_i386_XP.exe /full Kernrate_i386_XP.exe The older builds did not expose the user-visible symptom of "the app crashing" yet (due to different memory layout), but the heap corruption was already happening in all of them. This is a squashed backport of: 0.4.14-RC-92-gd3e301e28b
(the actual fix) 0.4.14-RC-93-g651a011548
(fix for compiling on GCC RosBE *Lin* 2.1.2 carrier-releaser) 0.4.14-release-24-g57efac32b1
(just a whitespace addendum)
This commit is contained in:
parent
abf5d21bc2
commit
e67f2d36f7
1 changed files with 43 additions and 30 deletions
|
@ -174,6 +174,37 @@ struct cpu* cpu_find(DWORD machine)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static WCHAR *make_default_search_path(void)
|
||||
{
|
||||
WCHAR* search_path;
|
||||
unsigned size;
|
||||
unsigned len;
|
||||
static const WCHAR sym_path[] = {'_','N','T','_','S','Y','M','B','O','L','_','P','A','T','H',0};
|
||||
static const WCHAR alt_sym_path[] = {'_','N','T','_','A','L','T','E','R','N','A','T','E','_','S','Y','M','B','O','L','_','P','A','T','H',0};
|
||||
|
||||
size = 1;
|
||||
search_path = HeapAlloc(GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR));
|
||||
search_path[0] = '.';
|
||||
search_path[1] = 0;
|
||||
|
||||
len = GetEnvironmentVariableW(sym_path, NULL, 0);
|
||||
if (len)
|
||||
{
|
||||
search_path = HeapReAlloc(GetProcessHeap(), 0, search_path, (size + 1 + len + 1) * sizeof(WCHAR));
|
||||
search_path[size] = ';';
|
||||
GetEnvironmentVariableW(sym_path, search_path + size + 1, len);
|
||||
size += 1 + len;
|
||||
}
|
||||
len = GetEnvironmentVariableW(alt_sym_path, NULL, 0);
|
||||
if (len)
|
||||
{
|
||||
search_path = HeapReAlloc(GetProcessHeap(), 0, search_path, (size + 1 + len + 1) * sizeof(WCHAR));
|
||||
search_path[size] = ';';
|
||||
GetEnvironmentVariableW(alt_sym_path, search_path + size + 1, len);
|
||||
}
|
||||
return search_path;
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
* SymSetSearchPathW (DBGHELP.@)
|
||||
*
|
||||
|
@ -200,14 +231,20 @@ BOOL WINAPI SymSetSearchPath(HANDLE hProcess, PCSTR searchPath)
|
|||
{
|
||||
BOOL ret = FALSE;
|
||||
unsigned len;
|
||||
WCHAR* sp;
|
||||
WCHAR* sp = NULL;
|
||||
|
||||
len = MultiByteToWideChar(CP_ACP, 0, searchPath, -1, NULL, 0);
|
||||
if ((sp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
|
||||
if (searchPath)
|
||||
{
|
||||
len = MultiByteToWideChar(CP_ACP, 0, searchPath, -1, NULL, 0);
|
||||
sp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
||||
if (!sp) return FALSE;
|
||||
MultiByteToWideChar(CP_ACP, 0, searchPath, -1, sp, len);
|
||||
}
|
||||
|
||||
ret = SymSetSearchPathW(hProcess, sp);
|
||||
ret = SymSetSearchPathW(hProcess, sp);
|
||||
|
||||
if (searchPath)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, sp);
|
||||
}
|
||||
return ret;
|
||||
|
@ -334,38 +371,14 @@ BOOL WINAPI SymInitializeW(HANDLE hProcess, PCWSTR UserSearchPath, BOOL fInvadeP
|
|||
}
|
||||
else
|
||||
{
|
||||
unsigned size;
|
||||
unsigned len;
|
||||
static const WCHAR sym_path[] = {'_','N','T','_','S','Y','M','B','O','L','_','P','A','T','H',0};
|
||||
static const WCHAR alt_sym_path[] = {'_','N','T','_','A','L','T','E','R','N','A','T','E','_','S','Y','M','B','O','L','_','P','A','T','H',0};
|
||||
|
||||
pcs->search_path = HeapAlloc(GetProcessHeap(), 0, (len = MAX_PATH) * sizeof(WCHAR));
|
||||
while ((size = GetCurrentDirectoryW(len, pcs->search_path)) >= len)
|
||||
pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, (len *= 2) * sizeof(WCHAR));
|
||||
pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, (size + 1) * sizeof(WCHAR));
|
||||
|
||||
len = GetEnvironmentVariableW(sym_path, NULL, 0);
|
||||
if (len)
|
||||
{
|
||||
pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, (size + 1 + len + 1) * sizeof(WCHAR));
|
||||
pcs->search_path[size] = ';';
|
||||
GetEnvironmentVariableW(sym_path, pcs->search_path + size + 1, len);
|
||||
size += 1 + len;
|
||||
}
|
||||
len = GetEnvironmentVariableW(alt_sym_path, NULL, 0);
|
||||
if (len)
|
||||
{
|
||||
pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, (size + 1 + len + 1) * sizeof(WCHAR));
|
||||
pcs->search_path[size] = ';';
|
||||
GetEnvironmentVariableW(alt_sym_path, pcs->search_path + size + 1, len);
|
||||
}
|
||||
pcs->search_path = make_default_search_path();
|
||||
}
|
||||
|
||||
pcs->lmodules = NULL;
|
||||
pcs->dbg_hdr_addr = 0;
|
||||
pcs->next = process_first;
|
||||
process_first = pcs;
|
||||
|
||||
|
||||
#ifndef DBGHELP_STATIC_LIB
|
||||
if (check_live_target(pcs))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue