Core/CrashHandler: Fix char[] without '\0' handling

Fix char[] without a NULL character '\0' in the array reading over the char[] bounds

(cherry picked from commit fd844e3d7e)
This commit is contained in:
jackpoz
2015-02-27 21:31:30 +01:00
committed by Nayd
parent 8b7dabab21
commit 1a583703c5
2 changed files with 11 additions and 5 deletions

View File

@@ -1068,7 +1068,7 @@ bool logChildren)
{
case btChar:
case btStdString:
FormatOutputValue(buffer, basicType, length, (PVOID)offset, sizeof(buffer));
FormatOutputValue(buffer, basicType, length, (PVOID)offset, sizeof(buffer), elementsCount);
symbolDetails.top().Value = buffer;
break;
default:
@@ -1196,7 +1196,8 @@ void WheatyExceptionReport::FormatOutputValue(char * pszCurrBuffer,
BasicType basicType,
DWORD64 length,
PVOID pAddress,
size_t bufferSize)
size_t bufferSize,
size_t countOverride)
{
__try
{
@@ -1204,10 +1205,15 @@ size_t bufferSize)
{
case btChar:
{
if (strlen((char*)pAddress) > bufferSize - 6)
// Special case handling for char[] type
if (countOverride != 0)
length = countOverride;
else
length = strlen((char*)pAddress);
if (length > bufferSize - 6)
pszCurrBuffer += sprintf(pszCurrBuffer, "\"%.*s...\"", bufferSize - 6, (char*)pAddress);
else
pszCurrBuffer += sprintf(pszCurrBuffer, "\"%s\"", (char*)pAddress);
pszCurrBuffer += sprintf(pszCurrBuffer, "\"%.*s\"", length, (char*)pAddress);
break;
}
case btStdString:

View File

@@ -172,7 +172,7 @@ class WheatyExceptionReport
static char * DumpTypeIndex(char *, DWORD64, DWORD, unsigned, DWORD_PTR, bool &, const char*, char*, bool, bool);
static void FormatOutputValue(char * pszCurrBuffer, BasicType basicType, DWORD64 length, PVOID pAddress, size_t bufferSize);
static void FormatOutputValue(char * pszCurrBuffer, BasicType basicType, DWORD64 length, PVOID pAddress, size_t bufferSize, size_t countOverride = 0);
static BasicType GetBasicType(DWORD typeIndex, DWORD64 modBase);
static DWORD_PTR DereferenceUnsafePointer(DWORD_PTR address);