You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HANDLE hFile = CreateFileA("Andrew.dmp", GENERIC_ALL, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); //Create the dmp file
if (!hFile)
! This check is incorrect. If CreateFileA fails, hFile will be INVALID_HANDLE_VALUE which is -1 not 0.
{
printf("Failed to write dump: Invalid dump file\n");
}
AndrewSpecial should call CloseHandle on hProc to avoid a handle leak. There are a couple of code paths that exit the function without closing the handle.
Issue 1
GetProcId
does not close process snapshot in early returnDWORD GetProcId(const wchar_t* ProcName) { PROCESSENTRY32 pe32; HANDLE hSnapshot = NULL; pe32.dwSize = sizeof(PROCESSENTRY32); hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (Process32First(hSnapshot, &pe32)) { do { if (wcscmp(pe32.szExeFile, ProcName) == 0) { + CloseHandle(hSnapshot); return pe32.th32ProcessID; break; } } while (Process32Next(hSnapshot, &pe32)); } if (hSnapshot != INVALID_HANDLE_VALUE) CloseHandle(hSnapshot); return NULL; }
AndrewSpecial/AndrewSpecial.cpp
Line 15 in 81f7cdb
Issue 2
Incorrect check on CreateFile API
HANDLE hFile = CreateFileA("Andrew.dmp", GENERIC_ALL, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); //Create the dmp file if (!hFile) ! This check is incorrect. If CreateFileA fails, hFile will be INVALID_HANDLE_VALUE which is -1 not 0. { printf("Failed to write dump: Invalid dump file\n"); }
AndrewSpecial/AndrewSpecial.cpp
Line 154 in 81f7cdb
Issue 3
AndrewSpecial
should callCloseHandle
onhProc
to avoid a handle leak. There are a couple of code paths that exit the function without closing the handle.AndrewSpecial/AndrewSpecial.cpp
Line 181 in 81f7cdb
AndrewSpecial/AndrewSpecial.cpp
Line 194 in 81f7cdb
AndrewSpecial/AndrewSpecial.cpp
Line 181 in 81f7cdb
The text was updated successfully, but these errors were encountered: