Skip to content

Commit

Permalink
Few code fixes, mem/resource leaks, possible buffer overflows.
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen authored and perim committed Dec 16, 2017
1 parent 7b022c5 commit 1327062
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/exceptionhandler/exceptionhandler.cpp
Expand Up @@ -758,6 +758,7 @@ static bool fetchProgramPath(char *const programPath, size_t const bufSize, cons
return false;
}

programPath[bytesRead] = 0;
// Cut of the linefeed (and everything following it) if it's present.
linefeed = strchr(programPath, '\n');
if (linefeed)
Expand Down
1 change: 1 addition & 0 deletions lib/framework/crc.cpp
Expand Up @@ -780,6 +780,7 @@ EcKey EcKey::generate()
{
// uECC_make_key failed
debug(LOG_ERROR, "Failed to generate key pair");
delete key;
return EcKey();
}
assert(genResult == 1);
Expand Down
1 change: 1 addition & 0 deletions lib/ivis_opengl/imdload.cpp
Expand Up @@ -724,6 +724,7 @@ static iIMDShape *_imd_load_level(const QString &filename, const char **ppFileDa
if (sscanf(pFileData, "%255s %d%n", buffer, &s->npolys, &cnt) != 2)
{
debug(LOG_ERROR, "_imd_load_level(3): file corrupt");
delete s;
return nullptr;
}
pFileData += cnt;
Expand Down
10 changes: 7 additions & 3 deletions lib/script/interpreter.cpp
Expand Up @@ -296,6 +296,7 @@ bool interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
bool bStop = false, bEvent = false;
UDWORD callDepth = 0;
bool bTraceOn = false; //enable to debug function/event calls
size_t last_called_script_eventsz = sizeof(last_called_script_event);

ASSERT(psContext != nullptr, "Invalid context pointer");

Expand Down Expand Up @@ -345,7 +346,8 @@ bool interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
bCurCallerIsEvent = false;

// find the debug info for the trigger
strcpy(last_called_script_event, eventGetTriggerID(psProg, index));
strncpy(last_called_script_event, eventGetTriggerID(psProg, index), last_called_script_eventsz - 1);
last_called_script_event[last_called_script_eventsz - 1] = 0;

if (bTraceOn)
{
Expand All @@ -367,7 +369,8 @@ bool interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
bCurCallerIsEvent = true;

// remember last called event/function
strcpy(last_called_script_event, eventGetEventID(psProg, index));
strncpy(last_called_script_event, eventGetEventID(psProg, index), last_called_script_eventsz - 1);
last_called_script_event[last_called_script_eventsz - 1] = 0;

if (bTraceOn)
{
Expand Down Expand Up @@ -848,7 +851,8 @@ bool interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
}

//remember last called event/index
strcpy(last_called_script_event, eventGetEventID(psProg, CurEvent));
strncpy(last_called_script_event, eventGetEventID(psProg, CurEvent), last_called_script_eventsz - 1);
last_called_script_event[last_called_script_eventsz - 1]= 0;

if (bTraceOn)
{
Expand Down
2 changes: 1 addition & 1 deletion po/el.po
Expand Up @@ -13232,7 +13232,7 @@ msgstr[1] "%s - Ανατέθηκαν %u μονάδες - Σημεία %d/%d"
#, c-format
msgid "%s - %u Unit assigned - Damage %3.0f%%"
msgid_plural "%s - %u Units assigned - Hitpoints %d/%d"
msgstr[0] "%s - Ανατέθηκε %u μονάδα - φθορά %3.0f%%"
msgstr[0] "%s - Ανατέθηκε %u μονάδα - φθορά %d/%d%%"
msgstr[1] "%s - Ανατέθηκαν %u μονάδες - Σημεία %d/%d"

#: src/structure.cpp:5495
Expand Down

0 comments on commit 1327062

Please sign in to comment.