Browse Source

Fixed heap corruption in string retrievement, also avoid runtime error if string doesnt fit buffer

tags/0.2
Ludwig Frühschütz 3 years ago
parent
commit
db4ca91180
2 changed files with 5 additions and 2 deletions
  1. +4
    -1
      OSC2AHK/dllmain.cpp
  2. +1
    -1
      msgtest.ahk

+ 4
- 1
OSC2AHK/dllmain.cpp View File

@ -156,7 +156,10 @@ DLLEXPORT char* getStringData(char* targetString, unsigned int targetSize, unsig
{
if (storedStrings[i].id == stringId)
{
strcpy_s(targetString, targetSize, storedStrings[i].string.c_str());
if (storedStrings[i].string.length() < targetSize) //Avoid runtime error.
strcpy_s(targetString, targetSize, storedStrings[i].string.c_str());
else
strcpy_s(targetString, targetSize, "\0"); //String doesnt fit, return empty string"
storedStrings.erase(storedStrings.begin() + i);
return targetString;
}


+ 1
- 1
msgtest.ahk View File

@ -48,7 +48,7 @@ msghandlerString(wParam, lParam, msg, hwnd) {
stdout.Write("msghandlerString: ")
VarSetCapacity(theStr, 20)
theStr := DllCall("OSC2AHK.dll\getStringData", AStr, theStr, UInt, 20, UInt, lParam, "Cdecl AStr")
theStr := DllCall("OSC2AHK.dll\getStringData", str, theStr, UInt, 20, UInt, lParam, AStr)
stdout.WriteLine(theStr)
stdout.Close()


Loading…
Cancel
Save