Skip to content

Commit aeb96d2

Browse files
committed
none
1 parent 9e53fe5 commit aeb96d2

37 files changed

+331
-240
lines changed

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/AppOfflineApplication.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ HRESULT AppOfflineApplication::CreateHandler(IHttpContext* pHttpContext, IREQUES
1212
try
1313
{
1414
auto handler = std::make_unique<AppOfflineHandler>(*pHttpContext, m_strAppOfflineContent);
15+
// 'Don't return a pointer that may be invalid'
16+
// We use make_unique to prevent memory leaks in case of exception during ctor and then release it so we don't delete the pointer
17+
#pragma warning(suppress: 26487)
1518
*pRequestHandler = handler.release();
1619
}
1720
CATCH_RETURN();

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/ModuleEnvironment.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
extern DWORD g_dwIISServerVersion;
1010

1111
static std::wstring GetIISVersion() {
12-
int major = (int)(g_dwIISServerVersion >> 16);
13-
int minor = (int)(g_dwIISServerVersion & 0xffff);
12+
const int major = (int)(g_dwIISServerVersion >> 16);
13+
const int minor = (int)(g_dwIISServerVersion & 0xffff);
1414

1515
std::wstringstream version;
1616
version << major << "." << minor;
@@ -44,14 +44,17 @@ void SetApplicationEnvironmentVariables(_In_ IHttpServer &server, _In_ IHttpCont
4444

4545
IHttpServer2* server2;
4646
if (SUCCEEDED(HttpGetExtendedInterface(&server, &server, &server2))) {
47+
// GetAppPoolConfigFile likely returns a 0 terminating string but the SAL annotations don't state that, we should probably change the code
48+
// just to be safe
49+
#pragma warning(suppress: 6387)
4750
SetEnvironmentVariable(L"ASPNETCORE_IIS_APP_POOL_CONFIG_FILE", server2->GetAppPoolConfigFile());
4851
}
4952

50-
IHttpSite* site = pHttpContext.GetSite();
53+
const IHttpSite* site = pHttpContext.GetSite();
5154
SetEnvironmentVariable(L"ASPNETCORE_IIS_SITE_NAME", site->GetSiteName());
5255
SetEnvironmentVariable(L"ASPNETCORE_IIS_SITE_ID", std::to_wstring(site->GetSiteId()).c_str());
5356

54-
IHttpApplication* app = pHttpContext.GetApplication();
57+
const IHttpApplication* app = pHttpContext.GetApplication();
5558
SetEnvironmentVariable(L"ASPNETCORE_IIS_APP_CONFIG_PATH", app->GetAppConfigPath());
5659
SetEnvironmentVariable(L"ASPNETCORE_IIS_APPLICATION_ID", app->GetApplicationId());
5760
SetEnvironmentVariable(L"ASPNETCORE_IIS_APPLICATION_VIRTUAL_PATH", ToVirtualPath(app->GetAppConfigPath()).c_str());

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/ShimOptions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ ShimOptions::ShimOptions(const ConfigurationSource &configurationSource) :
7979
m_strArguments = Environment::GetEnvironmentVariableValue(CS_ANCM_LAUNCHER_ARGS)
8080
.value_or(m_strArguments);
8181

82-
auto detailedErrorsEnabled = equals_ignore_case(L"1", detailedErrors) || equals_ignore_case(L"true", detailedErrors);
83-
auto aspnetCoreEnvironmentEnabled = equals_ignore_case(L"Development", aspnetCoreEnvironment);
84-
auto dotnetEnvironmentEnabled = equals_ignore_case(L"Development", dotnetEnvironment);
82+
const auto detailedErrorsEnabled = equals_ignore_case(L"1", detailedErrors) || equals_ignore_case(L"true", detailedErrors);
83+
const auto aspnetCoreEnvironmentEnabled = equals_ignore_case(L"Development", aspnetCoreEnvironment);
84+
const auto dotnetEnvironmentEnabled = equals_ignore_case(L"Development", dotnetEnvironment);
8585

8686
m_fShowDetailedErrors = detailedErrorsEnabled || aspnetCoreEnvironmentEnabled || dotnetEnvironmentEnabled;
8787

@@ -111,7 +111,7 @@ ShimOptions::ShimOptions(const ConfigurationSource &configurationSource) :
111111

112112
void ShimOptions::SetShutdownDelay(const std::wstring& shutdownDelay)
113113
{
114-
auto millsecondsValue = std::stoi(shutdownDelay);
114+
const auto millsecondsValue = std::stoi(shutdownDelay);
115115
if (millsecondsValue < 0)
116116
{
117117
throw ConfigurationLoadException(format(

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ APPLICATION_INFO::CreateApplication(IHttpContext& pHttpContext)
116116
pHttpApplication.GetApplicationId(),
117117
hr);
118118

119-
auto page = ANCM_ERROR_PAGE;
119+
constexpr auto page = ANCM_ERROR_PAGE;
120120
std::string responseContent;
121121
if (options.QueryShowDetailedErrors())
122122
{
@@ -301,7 +301,7 @@ APPLICATION_INFO::HandleShadowCopy(const ShimOptions& options, IHttpContext& pHt
301301
auto shadowCopyBaseDirectory = std::filesystem::directory_entry(shadowCopyPath);
302302
if (!shadowCopyBaseDirectory.exists())
303303
{
304-
CreateDirectory(shadowCopyBaseDirectory.path().wstring().c_str(), NULL);
304+
CreateDirectory(shadowCopyBaseDirectory.path().wstring().c_str(), nullptr);
305305
}
306306

307307
for (auto& entry : std::filesystem::directory_iterator(shadowCopyPath))
@@ -311,7 +311,7 @@ APPLICATION_INFO::HandleShadowCopy(const ShimOptions& options, IHttpContext& pHt
311311
try
312312
{
313313
auto tempDirName = entry.path().filename().string();
314-
int intFileName = std::stoi(tempDirName);
314+
const int intFileName = std::stoi(tempDirName);
315315
if (intFileName > directoryName)
316316
{
317317
directoryName = intFileName;
@@ -334,7 +334,7 @@ APPLICATION_INFO::HandleShadowCopy(const ShimOptions& options, IHttpContext& pHt
334334
// Avoid using canonical for shadowCopyBaseDirectory
335335
// It could expand to a network drive, or an expanded link folder path
336336
// We already made it an absolute path relative to the physicalPath above
337-
HRESULT hr = Environment::CopyToDirectory(physicalPath, shadowCopyPath, options.QueryCleanShadowCopyDirectory(), shadowCopyBaseDirectory.path(), copiedFileCount);
337+
const HRESULT hr = Environment::CopyToDirectory(physicalPath, shadowCopyPath, options.QueryCleanShadowCopyDirectory(), shadowCopyBaseDirectory.path(), copiedFileCount);
338338

339339
LOG_INFOF(L"Finished copying %d files to shadow copy directory %ls.", copiedFileCount, shadowCopyBaseDirectory.path().c_str());
340340

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/dllmain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ BOOL WINAPI DllMain(HMODULE hModule,
5757
// this is a bug in IIS. To try to avoid AVs, we will set a global flag
5858
g_fInShutdown = TRUE;
5959
StaticCleanup();
60+
break;
6061
default:
6162
break;
6263
}

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/globalmodule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ASPNET_CORE_GLOBAL_MODULE : NonCopyable, public CGlobalModule
7575
// IIS will actually stop giving us new requests and queue them instead for processing by the new app process.
7676
m_shutdown = std::thread([this]()
7777
{
78-
auto delay = m_pApplicationManager->GetShutdownDelay();
78+
const auto delay = m_pApplicationManager->GetShutdownDelay();
7979
LOG_INFOF(L"Shutdown starting in %d ms.", delay.count());
8080
// Delay so that any incoming requests while we're returning from OnGlobalStopListening are allowed to be processed
8181
std::this_thread::sleep_for(delay);

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/ErrorContext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
struct ErrorContext
77
{
8+
ErrorContext() :
9+
detailedErrorContent(),
10+
generalErrorType(),
11+
errorReason(),
12+
statusCode(),
13+
subStatusCode()
14+
{}
15+
816
// TODO consider adding HRESULT here
917
std::string detailedErrorContent;
1018
USHORT statusCode;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ void HostFxr::Load(const std::wstring& location)
8787
}
8888
}
8989

90+
// No array to pointer decay
91+
// This is in reference to main taking PCWSTR argv[] and the analyzer wanting us to use span instead
92+
#pragma warning(suppress: 26485)
9093
void HostFxr::SetMain(hostfxr_main_fn hostfxr_main_fn)
9194
{
9295
m_hostfxr_main_fn = hostfxr_main_fn;
@@ -114,7 +117,7 @@ HostFxrErrorRedirector HostFxr::RedirectOutput(RedirectionOutput* writer) const
114117
return HostFxrErrorRedirector(m_corehost_set_error_writer_fn, writer);
115118
}
116119

117-
int HostFxr::InitializeForApp(int argc, PCWSTR* argv, const std::wstring& dotnetExe) const noexcept
120+
int HostFxr::InitializeForApp(int argc, PCWSTR* argv, const std::wstring& dotnetExe) const
118121
{
119122
if (m_hostfxr_initialize_for_dotnet_commandline_fn == nullptr || m_hostfxr_main_fn != nullptr)
120123
{

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxr.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ typedef int(*hostfxr_get_runtime_property_value_fn)(void* host_context_handle, P
3030
typedef int(*hostfxr_run_app_fn)(void* host_context_handle);
3131
typedef int(*hostfxr_close_fn)(void* hostfxr_context_handle);
3232

33-
const int AppArgNotRunnable = 0x80008094;
33+
constexpr int AppArgNotRunnable = 0x80008094;
3434

3535
class HostFxrErrorRedirector: NonCopyable
3636
{
@@ -53,14 +53,22 @@ class HostFxr: NonCopyable
5353
{
5454
}
5555

56+
// No array to pointer decay
57+
// This is in reference to main taking PCWSTR argv[] and the analyzer wanting us to use span instead
58+
#pragma warning(suppress: 26485)
5659
HostFxr(
5760
hostfxr_main_fn hostfxr_main_fn,
5861
hostfxr_get_native_search_directories_fn hostfxr_get_native_search_directories_fn,
5962
corehost_set_error_writer_fn corehost_set_error_writer_fn) noexcept
6063
: m_hostfxr_main_fn(hostfxr_main_fn),
6164
m_hostfxr_get_native_search_directories_fn(hostfxr_get_native_search_directories_fn),
6265
m_corehost_set_error_writer_fn(corehost_set_error_writer_fn),
63-
m_host_context_handle(nullptr)
66+
m_host_context_handle(nullptr),
67+
m_hostfxr_close_fn(nullptr),
68+
m_hostfxr_get_runtime_property_value_fn(nullptr),
69+
m_hostfxr_initialize_for_dotnet_commandline_fn(nullptr),
70+
m_hostfxr_run_app_fn(nullptr),
71+
m_hostfxr_set_runtime_property_value_fn(nullptr)
6472
{
6573
}
6674

@@ -78,7 +86,7 @@ class HostFxr: NonCopyable
7886
HostFxrErrorRedirector RedirectOutput(RedirectionOutput* writer) const noexcept;
7987
int SetRuntimePropertyValue(PCWSTR name, PCWSTR value) const noexcept;
8088
int GetRuntimePropertyValue(PCWSTR name, PWSTR* value) const noexcept;
81-
int InitializeForApp(int argc, PCWSTR* argv, const std::wstring& m_dotnetExeKnownLocation) const noexcept;
89+
int InitializeForApp(int argc, PCWSTR* argv, const std::wstring& m_dotnetExeKnownLocation) const;
8290
void Close() const noexcept;
8391

8492
private:

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/ServerErrorApplication.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class ServerErrorApplication : public PollingAppOfflineApplication
2424

2525
HRESULT CreateHandler(IHttpContext *pHttpContext, IREQUEST_HANDLER ** pRequestHandler) override
2626
{
27+
// 'Don't return a pointer that may be invalid'
28+
// We use make_unique to prevent memory leaks and then release it so we don't delete the pointer
29+
#pragma warning(suppress: 26487)
2730
*pRequestHandler = std::make_unique<ServerErrorHandler>(*pHttpContext, m_statusCode, m_subStatusCode, m_statusText, m_HR, m_disableStartupPage, m_responseContent).release();
2831

2932
return S_OK;

0 commit comments

Comments
 (0)