Skip to content

Commit 75fdc60

Browse files
committed
Update Injector.cpp
1 parent a8215f4 commit 75fdc60

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Injector/Injector.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,11 @@ std::tstring Injector::GetPath( const std::tstring& ModuleName )
271271
if (PathIsRelative(ModuleName.c_str()))
272272
{
273273
std::vector<TCHAR> LoaderPath(MAX_PATH);
274-
if (!GetModuleFileName(NULL, &LoaderPath[0], static_cast<DWORD>(LoaderPath.size())) ||
275-
GetLastError() == ERROR_INSUFFICIENT_BUFFER)
274+
const DWORD LoaderPathLen = GetModuleFileName(NULL, &LoaderPath[0], static_cast<DWORD>(LoaderPath.size()));
275+
if (LoaderPathLen == 0)
276276
throw std::runtime_error("Could not get path to loader.");
277+
if (LoaderPathLen >= static_cast<DWORD>(LoaderPath.size()))
278+
throw std::runtime_error("Path to loader exceeds MAX_PATH and was truncated.");
277279

278280
std::tstring LoaderDir(&LoaderPath[0]);
279281
LoaderDir = LoaderDir.substr(0, LoaderDir.rfind(_T("\\")) + 1);

0 commit comments

Comments
 (0)