Skip to content

Commit

Permalink
fixup! Updates in ReadStringParam error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Oct 29, 2023
1 parent d1792ed commit dad53b7
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions source/CCustomOpcodeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ namespace CLEO
{
static char internal_buf[MAX_STR_LEN];
if (!buf) { buf = internal_buf; bufSize = MAX_STR_LEN; }
auto length = bufSize ? bufSize - 1 : 0; // max text length (minus terminator char)
const auto bufLength = bufSize ? bufSize - 1 : 0; // max text length (minus terminator char)

lastErrorMsg.clear();

Expand All @@ -676,12 +676,12 @@ namespace CLEO
}

char* str = opcodeParams[0].pcParam;
auto readLength = strlen(str);
auto length = strlen(str);

if(readLength > length)
if(length > bufLength)
{
lastErrorMsg = stringPrintf("Target buffer too small (%d) to read whole string (%d) from argument", length, readLength);
readLength = length; // clamp to target buffer size
lastErrorMsg = stringPrintf("Target buffer too small (%d) to read whole string (%d) from argument", bufLength, length);
length = bufLength; // clamp to target buffer size
}

if (length) strncpy(buf, str, length);
Expand Down Expand Up @@ -712,16 +712,16 @@ namespace CLEO
// prococess here as GetScriptStringParam can not obtain strings with lenght greater than 128
thread->IncPtr(1); // already processed paramType

DWORD readLength = (BYTE)*thread->GetBytePointer(); // as unsigned byte!
DWORD length = (BYTE)*thread->GetBytePointer(); // as unsigned byte!
thread->IncPtr(1); // length info

char* str = (char*)thread->GetBytePointer();
thread->IncPtr(readLength); // text data
thread->IncPtr(length); // text data

if (readLength > length)
if (length > bufLength)
{
lastErrorMsg = stringPrintf("Target buffer too small (%d) to read whole string (%d) from argument", length, readLength);
readLength = length; // clamp to target buffer size
lastErrorMsg = stringPrintf("Target buffer too small (%d) to read whole string (%d) from argument", bufLength, length);
length = bufLength; // clamp to target buffer size
}

if (length) strncpy(buf, str, length);
Expand Down

0 comments on commit dad53b7

Please sign in to comment.