• R/O
  • HTTP
  • SSH
  • HTTPS

ffftp: Commit

FFFTPのソースコードです。


Commit MetaInfo

Revision5479c0912351f56c0a87244b3028a5446c1164a4 (tree)
Zeit2012-01-21 07:58:27
AutorMoriguchi, Hirokazu <umorigu@gmai...>
CommiterMoriguchi, Hirokazu

Log Message

MessageUtil_GetUTF8StaticBinaryBlock function: Protect string memory area by using VirtualProtect API

Ändern Zusammenfassung

Diff

--- a/msgutil.c
+++ b/msgutil.c
@@ -71,12 +71,17 @@ const char* const MessageUtil_GetUTF8StaticBinaryBlock(const wchar_t* const ws,
7171 int index = strMapCount;
7272 char *beginPos = 0;
7373 int postSize = 0;
74+ DWORD flPrevProtect = 0;
7475 strMapCount++;
7576 pStrMap[index].ws = ws;
7677 pStrMap[index].u8size = newSize;
77- beginPos = (char*)malloc(newSize);
78+ beginPos = VirtualAlloc(NULL, newSize, MEM_COMMIT, PAGE_READWRITE);
7879 pStrMap[index].u8s = beginPos;
7980 postSize = WideCharToMultiByte(CP_UTF8, 0, ws, ws_area_length, beginPos, newSize, NULL, NULL);
81+ if (!VirtualProtect(beginPos, newSize, PAGE_READONLY, &flPrevProtect))
82+ {
83+ // 失敗した
84+ }
8085 pResult = beginPos;
8186
8287 // pStrMap ソートする
@@ -106,7 +111,7 @@ void MessageUtil_FreeUTF8StaticBinaryBlocks()
106111 EnterCriticalSection(&g_msgUtilLLock);
107112 for (i = 0; i < strMapCount; i++)
108113 {
109- free(pStrMap[i].u8s);
114+ VirtualFree(pStrMap[i].u8s, pStrMap[i].u8size, MEM_DECOMMIT);
110115 }
111116 if (pStrMap)
112117 {
Show on old repository browser