File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
src/Servers/IIS/AspNetCoreModuleV2/CommonLib Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -87,10 +87,21 @@ std::wstring Environment::GetCurrentDirectoryValue()
8787
8888std::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 }
You can’t perform that action at this time.
0 commit comments