Bug 1435827 part 4/9: Adding GetModuleFullPath to WinUtils.cpp;r=aklotz

A wrapper for ::GetModuleFileNameW() is needed in multiple places for the
purpose of evaluating and processing untrusted DLLs. This adds the appropriate
wrapper to WinUtils.cpp

Depends on D6240

Differential Revision: https://phabricator.services.mozilla.com/D9163

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Carl Corcoran 2018-11-02 07:59:15 +00:00
Родитель d0a2ed0652
Коммит 5ae1f207a6
2 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -2151,6 +2151,30 @@ WinUtils::RunningFromANetworkDrive()
return (::GetDriveTypeW(volPath) == DRIVE_REMOTE);
}
/* static */
bool
WinUtils::GetModuleFullPath(HMODULE aModuleHandle, nsAString& aPath)
{
size_t bufferSize = MAX_PATH;
size_t len = 0;
while (true) {
aPath.SetLength(bufferSize);
len = (size_t)::GetModuleFileNameW(aModuleHandle,
(char16ptr_t)aPath.BeginWriting(),
bufferSize);
if (!len) {
return false;
}
if (len == bufferSize && ::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
bufferSize *= 2;
continue;
}
aPath.Truncate(len);
break;
}
return true;
}
/* static */
bool WinUtils::CanonicalizePath(nsAString& aPath)
{

Просмотреть файл

@ -511,6 +511,15 @@ public:
// Use the one above!
static nsresult WriteBitmap(nsIFile* aFile, imgIContainer* aImage);
/**
* Wrapper for ::GetModuleFileNameW().
* @param aModuleHandle [in] The handle of a loaded module
* @param aPath [out] receives the full path of the module specified
* by aModuleBase.
* @return true if aPath was successfully populated.
*/
static bool GetModuleFullPath(HMODULE aModuleHandle, nsAString& aPath);
/**
* Wrapper for PathCanonicalize().
* Upon success, the resulting output string length is <= MAX_PATH.