Skip to content

Commit 94422d3

Browse files
authored
Merge pull request #494 from GeneralsOnlineDevelopmentTeam/seer/bugfix/safe-string-ops-stackdump
bugfix(system): Prevent buffer overflows and uninitialized memory in stack dump and exception handling
2 parents 95de567 + 2009224 commit 94422d3

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

Core/Libraries/Source/WWVegas/WWLib/Except.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)
407407
/*
408408
** Scrap buffer for constructing dump strings
409409
*/
410-
char scrap [256];
410+
char scrap [256] = {};
411411

412412
/*
413413
** Clear out the dump buffer
@@ -712,7 +712,7 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)
712712
** Dump the bytes at EIP. This will make it easier to match the crash address with later versions of the game.
713713
*/
714714
DebugString("EIP bytes dump...\n");
715-
sprintf(scrap, "\r\nBytes at CS:EIP (%08X) : ", context->Eip);
715+
snprintf(scrap, ARRAY_SIZE(scrap), "\r\nBytes at CS:EIP (%08X) : ", context->Eip);
716716

717717
unsigned char *eip_ptr = (unsigned char *) (context->Eip);
718718
char bytestr[32];

Generals/Code/GameEngine/Source/Common/System/StackDump.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ void DumpExceptionInfo( unsigned int u, EXCEPTION_POINTERS* e_info )
608608
/*
609609
** Dump the bytes at EIP. This will make it easier to match the crash address with later versions of the game.
610610
*/
611-
char scrap[512];
611+
char scrap[512] = {};
612612
DOUBLE_DEBUG ( ("EIP bytes dump..."));
613613
wsprintf (scrap, "\nBytes at CS:EIP (%08X) : ", context->Eip);
614614

@@ -619,7 +619,7 @@ void DumpExceptionInfo( unsigned int u, EXCEPTION_POINTERS* e_info )
619619
{
620620
if (IsBadReadPtr(eip_ptr, 1))
621621
{
622-
lstrcat (scrap, "?? ");
622+
strlcat(scrap, "?? ", ARRAY_SIZE(scrap));
623623
}
624624
else
625625
{

GeneralsMD/Code/GameEngine/Source/Common/System/StackDump.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ void DumpExceptionInfo( unsigned int u, EXCEPTION_POINTERS* e_info )
608608
/*
609609
** Dump the bytes at EIP. This will make it easier to match the crash address with later versions of the game.
610610
*/
611-
char scrap[512];
611+
char scrap[512] = {};
612612
DOUBLE_DEBUG ( ("EIP bytes dump..."));
613613
wsprintf (scrap, "\nBytes at CS:EIP (%08X) : ", context->Eip);
614614

@@ -619,7 +619,7 @@ void DumpExceptionInfo( unsigned int u, EXCEPTION_POINTERS* e_info )
619619
{
620620
if (IsBadReadPtr(eip_ptr, 1))
621621
{
622-
lstrcat (scrap, "?? ");
622+
strlcat(scrap, "?? ", ARRAY_SIZE(scrap));
623623
}
624624
else
625625
{

0 commit comments

Comments
 (0)