8000 Use secure CRT functions for string copying. by fancycode · Pull Request #52 · fancycode/MemoryModule · GitHub
[go: up one dir, main page]

Skip to content

Use secure CRT functions for string copying. #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use secure CRT functions for string copying.
  • Loading branch information
fancycode committed Sep 20, 2016
commit 2ecf5b764b7e4a329919f8bc8077e50d4ca7b53f
19 changes: 9 additions & 10 deletions MemoryModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,19 +851,20 @@ static PIMAGE_RESOURCE_DIRECTORY_ENTRY _MemorySearchResourceEntry(
// using a pre-allocated array.
wchar_t _searchKeySpace[MAX_LOCAL_KEY_LENGTH+1];
LPWSTR _searchKey;
size_t _searchKeySize;
if (searchKeyLen > MAX_LOCAL_KEY_LENGTH) {
size_t _searchKeySize = (searchKeyLen + 1) * sizeof(wchar_t);
_searchKeySize = (searchKeyLen + 1) * sizeof(wchar_t);
_searchKey = (LPWSTR) malloc(_searchKeySize);
if (_searchKey == NULL) {
SetLastError(ERROR_OUTOFMEMORY);
return NULL;
}
} else {
_searchKey = &_searchKeySpace[0];
_searchKeySize = sizeof(_searchKeySpace);
}

mbstowcs(_searchKey, key, searchKeyLen);
_searchKey[searchKeyLen] = 0;
mbstowcs_s(NULL, _searchKey, _searchKeySize, key, searchKeyLen);
searchKey = _searchKey;
#endif
start = 0;
Expand Down Expand Up @@ -990,7 +991,7 @@ MemoryLoadStringEx(HMEMORYMODULE module, UINT id, LPTSTR buffer, int maxsize, WO
{
HMEMORYRSRC resource;
PIMAGE_RESOURCE_DIR_STRING_U data;
DWORD size;
int size;
if (maxsize == 0) {
return 0;
}
Expand All @@ -1013,15 +1014,13 @@ MemoryLoadStringEx(HMEMORYMODULE module, UINT id, LPTSTR buffer, int maxsize, WO
}

size = data->Length;
if (size >= (DWORD) maxsize) {
size = maxsize;
} else {
buffer[size] = 0;
if (size >= maxsize) {
size = maxsize - 1;
}
#if defined(UNICODE)
wcsncpy(buffer, data->NameString, size);
wcsncpy_s(buffer, maxsize, data->NameString, size);
#else
wcstombs(buffer, data->NameString, size);
wcstombs_s(NULL, buffer, maxsize, data->NameString, size);
#endif
return size;
}
Expand Down
0