Skip to content

Commit d73d6e8

Browse files
authored
Fix GetDllDirectory on 2008 (#6066)
1 parent 45d1c05 commit d73d6e8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Servers/IIS/src/AspNetCoreModuleV2/CommonLib/Environment.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,21 @@ std::wstring Environment::GetCurrentDirectoryValue()
8787

8888
std::wstring Environment::GetDllDirectoryValue()
8989
{
90+
// GetDllDirectory can return 0 in both the success case and the failure case, and it only sets last error when it fails.
91+
// This requires you to set the last error to ERROR_SUCCESS before calling it in order to detect failure.
92+
SetLastError(ERROR_SUCCESS);
93+
9094
DWORD requestedSize = GetDllDirectory(0, nullptr);
9195
if (requestedSize == 0)
9296
{
93-
throw std::system_error(GetLastError(), std::system_category(), "GetDllDirectory");
97+
if (GetLastError() != ERROR_SUCCESS)
98+
{
99+
throw std::system_error(GetLastError(), std::system_category(), "GetDllDirectory");
100+
}
101+
else
102+
{
103+
return L"";
104+
}
94105
}
95106

96107
std::wstring expandedStr;
@@ -99,7 +110,7 @@ std::wstring Environment::GetDllDirectoryValue()
99110
expandedStr.resize(requestedSize);
100111
requestedSize = GetDllDirectory(requestedSize, expandedStr.data());
101112
// 0 might be returned if GetDllDirectory is empty
102-
if (requestedSize == 0 && GetLastError() != 0)
113+
if (requestedSize == 0 && GetLastError() != ERROR_SUCCESS)
103114
{
104115
throw std::system_error(GetLastError(), std::system_category(), "GetDllDirectory");
105116
}

0 commit comments

Comments
 (0)