File tree 1 file changed +13
-2
lines changed
src/Servers/IIS/src/AspNetCoreModuleV2/CommonLib
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()
87
87
88
88
std::wstring Environment::GetDllDirectoryValue ()
89
89
{
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
+
90
94
DWORD requestedSize = GetDllDirectory (0 , nullptr );
91
95
if (requestedSize == 0 )
92
96
{
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
+ }
94
105
}
95
106
96
107
std::wstring expandedStr;
@@ -99,7 +110,7 @@ std::wstring Environment::GetDllDirectoryValue()
99
110
expandedStr.resize (requestedSize);
100
111
requestedSize = GetDllDirectory (requestedSize, expandedStr.data ());
101
112
// 0 might be returned if GetDllDirectory is empty
102
- if (requestedSize == 0 && GetLastError () != 0 )
113
+ if (requestedSize == 0 && GetLastError () != ERROR_SUCCESS )
103
114
{
104
115
throw std::system_error (GetLastError (), std::system_category (), " GetDllDirectory" );
105
116
}
You can’t perform that action at this time.
0 commit comments