Revision | 5479c0912351f56c0a87244b3028a5446c1164a4 (tree) |
---|---|
Time | 2012-01-21 07:58:27 |
Author | Moriguchi, Hirokazu <umorigu@gmai...> |
Commiter | Moriguchi, Hirokazu |
MessageUtil_GetUTF8StaticBinaryBlock function: Protect string memory area by using VirtualProtect API
@@ -71,12 +71,17 @@ const char* const MessageUtil_GetUTF8StaticBinaryBlock(const wchar_t* const ws, | ||
71 | 71 | int index = strMapCount; |
72 | 72 | char *beginPos = 0; |
73 | 73 | int postSize = 0; |
74 | + DWORD flPrevProtect = 0; | |
74 | 75 | strMapCount++; |
75 | 76 | pStrMap[index].ws = ws; |
76 | 77 | pStrMap[index].u8size = newSize; |
77 | - beginPos = (char*)malloc(newSize); | |
78 | + beginPos = VirtualAlloc(NULL, newSize, MEM_COMMIT, PAGE_READWRITE); | |
78 | 79 | pStrMap[index].u8s = beginPos; |
79 | 80 | postSize = WideCharToMultiByte(CP_UTF8, 0, ws, ws_area_length, beginPos, newSize, NULL, NULL); |
81 | + if (!VirtualProtect(beginPos, newSize, PAGE_READONLY, &flPrevProtect)) | |
82 | + { | |
83 | + // 失敗した | |
84 | + } | |
80 | 85 | pResult = beginPos; |
81 | 86 | |
82 | 87 | // pStrMap ソートする |
@@ -106,7 +111,7 @@ void MessageUtil_FreeUTF8StaticBinaryBlocks() | ||
106 | 111 | EnterCriticalSection(&g_msgUtilLLock); |
107 | 112 | for (i = 0; i < strMapCount; i++) |
108 | 113 | { |
109 | - free(pStrMap[i].u8s); | |
114 | + VirtualFree(pStrMap[i].u8s, pStrMap[i].u8size, MEM_DECOMMIT); | |
110 | 115 | } |
111 | 116 | if (pStrMap) |
112 | 117 | { |