From 613fbcc349a6e2f43aa65e28722e9054d41c04aa Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 5 Sep 2018 16:47:51 -0700 Subject: [PATCH] Enable code analysis on shim project (#1361) --- build/Build.Settings | 5 + .../AspNetCore/AppOfflineApplication.cpp | 9 +- .../AspNetCore/AppOfflineApplication.h | 2 +- .../AspNetCore/AppOfflineHandler.cpp | 4 +- .../AspNetCore/AppOfflineHandler.h | 4 +- .../AspNetCore/ApplicationFactory.h | 9 +- .../AspNetCore/AspNetCore.vcxproj | 4 +- .../AspNetCore/HandlerResolver.cpp | 25 +- .../AspNetCore/HandlerResolver.h | 12 +- .../PollingAppOfflineApplication.cpp | 4 +- .../AspNetCore/PollingAppOfflineApplication.h | 4 +- .../AspNetCore/ServerErrorApplication.h | 7 +- .../AspNetCore/ServerErrorHandler.h | 6 +- .../AspNetCore/ShimOptions.h | 12 +- .../AspNetCore/applicationinfo.cpp | 17 +- .../AspNetCore/applicationinfo.h | 14 +- .../AspNetCore/applicationmanager.cpp | 3 - .../AspNetCore/applicationmanager.h | 33 +- src/AspNetCoreModuleV2/AspNetCore/dllmain.cpp | 71 +-- .../AspNetCore/globalmodule.cpp | 16 +- .../AspNetCore/globalmodule.h | 18 +- .../AspNetCore/proxymodule.cpp | 37 +- .../AspNetCore/proxymodule.h | 24 +- src/AspNetCoreModuleV2/CommonLib/EventLog.cpp | 2 +- src/AspNetCoreModuleV2/CommonLib/EventLog.h | 24 +- .../CommonLib/FileOutputManager.cpp | 2 +- .../CommonLib/HandleWrapper.h | 26 +- .../CommonLib/IOutputManager.h | 2 +- .../CommonLib/ModuleHelpers.h | 21 +- .../CommonLib/NonCopyable.h | 4 +- .../CommonLib/ResultException.h | 19 + .../CommonLib/StdWrapper.cpp | 16 +- .../CommonLib/StringHelpers.h | 30 +- .../CommonLib/WebConfigConfigurationSource.h | 4 +- .../CommonLib/application.h | 12 +- src/AspNetCoreModuleV2/CommonLib/exceptions.h | 51 ++- src/AspNetCoreModuleV2/CommonLib/fx_ver.h | 14 +- .../CommonLib/hostfxroptions.h | 8 +- .../CommonLib/iapplication.h | 2 +- .../CommonLib/requesthandler.h | 4 +- src/AspNetCoreModuleV2/DefaultRules.ruleset | 432 ++++++++++++++++++ src/AspNetCoreModuleV2/IISLib/acache.cpp | 7 +- src/AspNetCoreModuleV2/IISLib/buffer.h | 5 + src/AspNetCoreModuleV2/IISLib/multisz.h | 7 +- src/AspNetCoreModuleV2/IISLib/percpu.h | 7 +- src/AspNetCoreModuleV2/IISLib/stringa.h | 6 + src/AspNetCoreModuleV2/IISLib/stringu.cpp | 22 +- src/AspNetCoreModuleV2/IISLib/stringu.h | 8 +- .../managedexports.cpp | 2 +- .../AppOfflineTrackingApplication.cpp | 2 +- 50 files changed, 793 insertions(+), 286 deletions(-) create mode 100644 src/AspNetCoreModuleV2/CommonLib/ResultException.h create mode 100644 src/AspNetCoreModuleV2/DefaultRules.ruleset diff --git a/build/Build.Settings b/build/Build.Settings index 9daccf4aaa..d60b07c269 100644 --- a/build/Build.Settings +++ b/build/Build.Settings @@ -20,6 +20,11 @@ false true + ..\DefaultRules.ruleset + false + + true + $(RunCodeAnalysis) diff --git a/src/AspNetCoreModuleV2/AspNetCore/AppOfflineApplication.cpp b/src/AspNetCoreModuleV2/AspNetCore/AppOfflineApplication.cpp index 49b2b07993..abae1963d5 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/AppOfflineApplication.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/AppOfflineApplication.cpp @@ -11,7 +11,8 @@ HRESULT AppOfflineApplication::CreateHandler(IHttpContext* pHttpContext, IREQUES { try { - *pRequestHandler = new AppOfflineHandler(pHttpContext, m_strAppOfflineContent); + auto handler = std::make_unique(*pHttpContext, m_strAppOfflineContent); + *pRequestHandler = handler.release(); } CATCH_RETURN(); @@ -44,9 +45,9 @@ HRESULT AppOfflineApplication::OnAppOfflineFound() if (li.LowPart > 0) { DWORD bytesRead = 0; - std::string pszBuff(li.LowPart + 1, '\0'); + std::string pszBuff(static_cast(li.LowPart) + 1, '\0'); - RETURN_LAST_ERROR_IF(!ReadFile(handle, pszBuff.data(), li.LowPart, &bytesRead, NULL)); + RETURN_LAST_ERROR_IF(!ReadFile(handle, pszBuff.data(), li.LowPart, &bytesRead, nullptr)); pszBuff.resize(bytesRead); m_strAppOfflineContent = pszBuff; @@ -55,7 +56,7 @@ HRESULT AppOfflineApplication::OnAppOfflineFound() return S_OK; } -bool AppOfflineApplication::ShouldBeStarted(IHttpApplication& pApplication) +bool AppOfflineApplication::ShouldBeStarted(const IHttpApplication& pApplication) { return FileExists(GetAppOfflineLocation(pApplication)); } diff --git a/src/AspNetCoreModuleV2/AspNetCore/AppOfflineApplication.h b/src/AspNetCoreModuleV2/AspNetCore/AppOfflineApplication.h index 71f79e5294..14399edaaa 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/AppOfflineApplication.h +++ b/src/AspNetCoreModuleV2/AspNetCore/AppOfflineApplication.h @@ -20,7 +20,7 @@ public: HRESULT OnAppOfflineFound() override; - static bool ShouldBeStarted(IHttpApplication& pApplication); + static bool ShouldBeStarted(const IHttpApplication& pApplication); private: std::string m_strAppOfflineContent; diff --git a/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.cpp b/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.cpp index 3efeb74463..f5098f71f6 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.cpp @@ -7,8 +7,8 @@ REQUEST_NOTIFICATION_STATUS AppOfflineHandler::OnExecuteRequestHandler() { - HTTP_DATA_CHUNK DataChunk; - IHttpResponse* pResponse = m_pContext->GetResponse(); + HTTP_DATA_CHUNK DataChunk {}; + auto pResponse = m_pContext.GetResponse(); DBG_ASSERT(pResponse); diff --git a/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.h b/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.h index 784a470915..e0ffd5d7cc 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.h +++ b/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.h @@ -9,7 +9,7 @@ class AppOfflineHandler: public REQUEST_HANDLER { public: - AppOfflineHandler(IHttpContext* pContext, const std::string appOfflineContent) + AppOfflineHandler(IHttpContext& pContext, const std::string appOfflineContent) : m_pContext(pContext), m_strAppOfflineContent(appOfflineContent) { @@ -18,6 +18,6 @@ public: REQUEST_NOTIFICATION_STATUS OnExecuteRequestHandler() override; private: - IHttpContext* m_pContext; + IHttpContext& m_pContext; std::string m_strAppOfflineContent; }; diff --git a/src/AspNetCoreModuleV2/AspNetCore/ApplicationFactory.h b/src/AspNetCoreModuleV2/AspNetCore/ApplicationFactory.h index 380b0de6cc..9d310438ef 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/ApplicationFactory.h +++ b/src/AspNetCoreModuleV2/AspNetCore/ApplicationFactory.h @@ -5,6 +5,7 @@ #include #include +#include #include "iapplication.h" #include "HandleWrapper.h" @@ -21,9 +22,9 @@ HRESULT class ApplicationFactory { public: - ApplicationFactory(HMODULE hRequestHandlerDll, std::wstring location, PFN_ASPNETCORE_CREATE_APPLICATION pfnAspNetCoreCreateApplication): + ApplicationFactory(HMODULE hRequestHandlerDll, std::wstring location, PFN_ASPNETCORE_CREATE_APPLICATION pfnAspNetCoreCreateApplication) noexcept: m_pfnAspNetCoreCreateApplication(pfnAspNetCoreCreateApplication), - m_location(location), + m_location(std::move(location)), m_hRequestHandlerDll(hRequestHandlerDll) { } @@ -31,10 +32,10 @@ public: HRESULT Execute( _In_ IHttpServer *pServer, _In_ IHttpApplication *pHttpApplication, - _Out_ IAPPLICATION **pApplication) const + _Outptr_ IAPPLICATION **pApplication) const noexcept { std::array parameters { - {"InProcessExeLocation", reinterpret_cast(m_location.data())} + {"InProcessExeLocation", m_location.data()} }; return m_pfnAspNetCoreCreateApplication(pServer, pHttpApplication, parameters.data(), static_cast(parameters.size()), pApplication); } diff --git a/src/AspNetCoreModuleV2/AspNetCore/AspNetCore.vcxproj b/src/AspNetCoreModuleV2/AspNetCore/AspNetCore.vcxproj index d700f7ed1b..b71ab41c83 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/AspNetCore.vcxproj +++ b/src/AspNetCoreModuleV2/AspNetCore/AspNetCore.vcxproj @@ -1,6 +1,5 @@ - + - Debug @@ -56,6 +55,7 @@ Unicode + diff --git a/src/AspNetCoreModuleV2/AspNetCore/HandlerResolver.cpp b/src/AspNetCoreModuleV2/AspNetCore/HandlerResolver.cpp index bd7dacfb34..4c98e60f11 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/HandlerResolver.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/HandlerResolver.cpp @@ -14,11 +14,12 @@ #include "resources.h" #include "ConfigurationLoadException.h" #include "WebConfigConfigurationSource.h" +#include "ModuleHelpers.h" const PCWSTR HandlerResolver::s_pwzAspnetcoreInProcessRequestHandlerName = L"aspnetcorev2_inprocess.dll"; const PCWSTR HandlerResolver::s_pwzAspnetcoreOutOfProcessRequestHandlerName = L"aspnetcorev2_outofprocess.dll"; -HandlerResolver::HandlerResolver(HMODULE hModule, IHttpServer &pServer) +HandlerResolver::HandlerResolver(HMODULE hModule, const IHttpServer &pServer) : m_hModule(hModule), m_pServer(pServer), m_loadedApplicationHostingModel(HOSTING_UNKNOWN) @@ -27,11 +28,11 @@ HandlerResolver::HandlerResolver(HMODULE hModule, IHttpServer &pServer) } HRESULT -HandlerResolver::LoadRequestHandlerAssembly(IHttpApplication &pApplication, ShimOptions& pConfiguration, std::unique_ptr& pApplicationFactory) +HandlerResolver::LoadRequestHandlerAssembly(const IHttpApplication &pApplication, const ShimOptions& pConfiguration, std::unique_ptr& pApplicationFactory) { - HRESULT hr; - PCWSTR pstrHandlerDllName; - bool preventUnload; + HRESULT hr = S_OK; + PCWSTR pstrHandlerDllName = nullptr; + bool preventUnload = false; if (pConfiguration.QueryHostingModel() == APP_HOSTING_MODEL::HOSTING_IN_PROCESS) { preventUnload = false; @@ -76,7 +77,7 @@ HandlerResolver::LoadRequestHandlerAssembly(IHttpApplication &pApplication, Shim hr = FindNativeAssemblyFromHostfxr(*options.get(), pstrHandlerDllName, handlerDllPath); outputManager->Stop(); - if (FAILED(hr) && m_hHostFxrDll != NULL) + if (FAILED(hr) && m_hHostFxrDll != nullptr) { STRA content; STRU struStdMsg; @@ -119,7 +120,7 @@ HandlerResolver::LoadRequestHandlerAssembly(IHttpApplication &pApplication, Shim RETURN_LAST_ERROR_IF_NULL(hRequestHandlerDll); } - auto pfnAspNetCoreCreateApplication = reinterpret_cast(GetProcAddress(hRequestHandlerDll, "CreateApplication")); + auto pfnAspNetCoreCreateApplication = ModuleHelpers::GetKnownProcAddress(hRequestHandlerDll, "CreateApplication"); RETURN_LAST_ERROR_IF_NULL(pfnAspNetCoreCreateApplication); pApplicationFactory = std::make_unique(hRequestHandlerDll.release(), location, pfnAspNetCoreCreateApplication); @@ -127,7 +128,7 @@ HandlerResolver::LoadRequestHandlerAssembly(IHttpApplication &pApplication, Shim } HRESULT -HandlerResolver::GetApplicationFactory(IHttpApplication &pApplication, std::unique_ptr& pApplicationFactory) +HandlerResolver::GetApplicationFactory(const IHttpApplication &pApplication, std::unique_ptr& pApplicationFactory) { try { @@ -189,7 +190,7 @@ void HandlerResolver::ResetHostingModel() HRESULT HandlerResolver::FindNativeAssemblyFromGlobalLocation( - ShimOptions& pConfiguration, + const ShimOptions& pConfiguration, PCWSTR pstrHandlerDllName, std::wstring& handlerDllPath ) @@ -225,20 +226,20 @@ HandlerResolver::FindNativeAssemblyFromGlobalLocation( // HRESULT HandlerResolver::FindNativeAssemblyFromHostfxr( - HOSTFXR_OPTIONS& hostfxrOptions, + const HOSTFXR_OPTIONS& hostfxrOptions, PCWSTR libraryName, std::wstring& handlerDllPath ) { std::wstring struNativeSearchPaths; - size_t intIndex; + size_t intIndex = 0; size_t intPrevIndex = 0; DWORD dwBufferSize = s_initialGetNativeSearchDirectoriesBufferSize; DWORD dwRequiredBufferSize = 0; RETURN_LAST_ERROR_IF_NULL(m_hHostFxrDll = LoadLibraryW(hostfxrOptions.GetHostFxrLocation().c_str())); - auto pFnHostFxrSearchDirectories = reinterpret_cast(GetProcAddress(m_hHostFxrDll, "hostfxr_get_native_search_directories")); + const auto pFnHostFxrSearchDirectories = ModuleHelpers::GetKnownProcAddress(m_hHostFxrDll, "hostfxr_get_native_search_directories"); if (pFnHostFxrSearchDirectories == nullptr) { EventLog::Error( diff --git a/src/AspNetCoreModuleV2/AspNetCore/HandlerResolver.h b/src/AspNetCoreModuleV2/AspNetCore/HandlerResolver.h index be927693ab..7b230a928f 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/HandlerResolver.h +++ b/src/AspNetCoreModuleV2/AspNetCore/HandlerResolver.h @@ -13,17 +13,17 @@ class HandlerResolver { public: - HandlerResolver(HMODULE hModule, IHttpServer &pServer); - HRESULT GetApplicationFactory(IHttpApplication &pApplication, std::unique_ptr& pApplicationFactory); + HandlerResolver(HMODULE hModule, const IHttpServer &pServer); + HRESULT GetApplicationFactory(const IHttpApplication &pApplication, std::unique_ptr& pApplicationFactory); void ResetHostingModel(); private: - HRESULT LoadRequestHandlerAssembly(IHttpApplication &pApplication, ShimOptions& pConfiguration, std::unique_ptr& pApplicationFactory); - HRESULT FindNativeAssemblyFromGlobalLocation(ShimOptions& pConfiguration, PCWSTR libraryName, std::wstring& handlerDllPath); - HRESULT FindNativeAssemblyFromHostfxr(HOSTFXR_OPTIONS& hostfxrOptions, PCWSTR libraryName, std::wstring& handlerDllPath); + HRESULT LoadRequestHandlerAssembly(const IHttpApplication &pApplication, const ShimOptions& pConfiguration, std::unique_ptr& pApplicationFactory); + HRESULT FindNativeAssemblyFromGlobalLocation(const ShimOptions& pConfiguration, PCWSTR libraryName, std::wstring& handlerDllPath); + HRESULT FindNativeAssemblyFromHostfxr(const HOSTFXR_OPTIONS& hostfxrOptions, PCWSTR libraryName, std::wstring& handlerDllPath); HMODULE m_hModule; - IHttpServer &m_pServer; + const IHttpServer &m_pServer; SRWLOCK m_requestHandlerLoadLock {}; std::wstring m_loadedApplicationId; diff --git a/src/AspNetCoreModuleV2/AspNetCore/PollingAppOfflineApplication.cpp b/src/AspNetCoreModuleV2/AspNetCore/PollingAppOfflineApplication.cpp index 1270319e8b..382950fde4 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/PollingAppOfflineApplication.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/PollingAppOfflineApplication.cpp @@ -44,12 +44,12 @@ PollingAppOfflineApplication::CheckAppOffline() } -std::filesystem::path PollingAppOfflineApplication::GetAppOfflineLocation(IHttpApplication& pApplication) +std::filesystem::path PollingAppOfflineApplication::GetAppOfflineLocation(const IHttpApplication& pApplication) { return std::filesystem::path(pApplication.GetApplicationPhysicalPath()) / "app_offline.htm"; } -bool PollingAppOfflineApplication::FileExists(const std::filesystem::path& path) +bool PollingAppOfflineApplication::FileExists(const std::filesystem::path& path) noexcept { std::error_code ec; return is_regular_file(path, ec) || ec.value() == ERROR_SHARING_VIOLATION; diff --git a/src/AspNetCoreModuleV2/AspNetCore/PollingAppOfflineApplication.h b/src/AspNetCoreModuleV2/AspNetCore/PollingAppOfflineApplication.h index 193a63e639..eadd0da3b8 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/PollingAppOfflineApplication.h +++ b/src/AspNetCoreModuleV2/AspNetCore/PollingAppOfflineApplication.h @@ -31,8 +31,8 @@ public: protected: std::filesystem::path m_appOfflineLocation; - static std::filesystem::path GetAppOfflineLocation(IHttpApplication& pApplication); - static bool FileExists(const std::filesystem::path& path); + static std::filesystem::path GetAppOfflineLocation(const IHttpApplication& pApplication); + static bool FileExists(const std::filesystem::path& path) noexcept; private: static const int c_appOfflineRefreshIntervalMS = 200; std::string m_strAppOfflineContent; diff --git a/src/AspNetCoreModuleV2/AspNetCore/ServerErrorApplication.h b/src/AspNetCoreModuleV2/AspNetCore/ServerErrorApplication.h index 2162075950..86a9a1a0e3 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/ServerErrorApplication.h +++ b/src/AspNetCoreModuleV2/AspNetCore/ServerErrorApplication.h @@ -17,13 +17,14 @@ public: ~ServerErrorApplication() = default; - HRESULT CreateHandler(IHttpContext * pHttpContext, IREQUEST_HANDLER ** pRequestHandler) override + HRESULT CreateHandler(IHttpContext *pHttpContext, IREQUEST_HANDLER ** pRequestHandler) override { - *pRequestHandler = new ServerErrorHandler(pHttpContext, m_HR); + auto handler = std::make_unique(*pHttpContext, m_HR); + *pRequestHandler = handler.release(); return S_OK; } - HRESULT OnAppOfflineFound() override { return S_OK; } + HRESULT OnAppOfflineFound() noexcept override { return S_OK; } private: HRESULT m_HR; }; diff --git a/src/AspNetCoreModuleV2/AspNetCore/ServerErrorHandler.h b/src/AspNetCoreModuleV2/AspNetCore/ServerErrorHandler.h index b3d917039d..10cf3ee049 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/ServerErrorHandler.h +++ b/src/AspNetCoreModuleV2/AspNetCore/ServerErrorHandler.h @@ -7,17 +7,17 @@ class ServerErrorHandler : public REQUEST_HANDLER { public: - ServerErrorHandler(IHttpContext* pContext, HRESULT hr) : m_pContext(pContext), m_HR(hr) + ServerErrorHandler(IHttpContext &pContext, HRESULT hr) : m_pContext(pContext), m_HR(hr) { } REQUEST_NOTIFICATION_STATUS OnExecuteRequestHandler() override { - m_pContext->GetResponse()->SetStatus(500, "Internal Server Error", 0, m_HR); + m_pContext.GetResponse()->SetStatus(500, "Internal Server Error", 0, m_HR); return RQ_NOTIFICATION_FINISH_REQUEST; } private: - IHttpContext * m_pContext; + IHttpContext &m_pContext; HRESULT m_HR; }; diff --git a/src/AspNetCoreModuleV2/AspNetCore/ShimOptions.h b/src/AspNetCoreModuleV2/AspNetCore/ShimOptions.h index f987e864ba..4b934ad9b4 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/ShimOptions.h +++ b/src/AspNetCoreModuleV2/AspNetCore/ShimOptions.h @@ -18,37 +18,37 @@ class ShimOptions: NonCopyable { public: const std::wstring& - QueryProcessPath() const + QueryProcessPath() const noexcept { return m_strProcessPath; } const std::wstring& - QueryArguments() const + QueryArguments() const noexcept { return m_strArguments; } APP_HOSTING_MODEL - QueryHostingModel() const + QueryHostingModel() const noexcept { return m_hostingModel; } const std::wstring& - QueryHandlerVersion() const + QueryHandlerVersion() const noexcept { return m_strHandlerVersion; } BOOL - QueryStdoutLogEnabled() const + QueryStdoutLogEnabled() const noexcept { return m_fStdoutLogEnabled; } const std::wstring& - QueryStdoutLogFile() const + QueryStdoutLogFile() const noexcept { return m_struStdoutLogFile; } diff --git a/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp b/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp index 9f2b20cf8e..fb558e52d0 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp @@ -13,14 +13,9 @@ #include "ServerErrorApplication.h" #include "AppOfflineApplication.h" -APPLICATION_INFO::~APPLICATION_INFO() -{ - ShutDownApplication(/* fServerInitiated */ false); -} - HRESULT APPLICATION_INFO::GetOrCreateApplication( - IHttpContext *pHttpContext, + IHttpContext& pHttpContext, std::unique_ptr& pApplication ) { @@ -28,7 +23,7 @@ APPLICATION_INFO::GetOrCreateApplication( SRWExclusiveLock lock(m_applicationLock); - auto& httpApplication = *pHttpContext->GetApplication(); + auto& httpApplication = *pHttpContext.GetApplication(); if (m_pApplication != nullptr) { @@ -51,7 +46,10 @@ APPLICATION_INFO::GetOrCreateApplication( if (AppOfflineApplication::ShouldBeStarted(httpApplication)) { LOG_INFO(L"Detected app_offline file, creating polling application"); + #pragma warning( push ) + #pragma warning ( disable : 26409 ) // Disable "Avoid using new", using custom deleter here m_pApplication.reset(new AppOfflineApplication(httpApplication)); + #pragma warning( pop ) } else { @@ -77,8 +75,11 @@ Finished: ASPNETCORE_EVENT_ADD_APPLICATION_ERROR_MSG, httpApplication.GetApplicationId(), hr); - + + #pragma warning( push ) + #pragma warning ( disable : 26409 ) // Disable "Avoid using new", using custom deleter here m_pApplication.reset(new ServerErrorApplication(httpApplication, hr)); + #pragma warning( pop ) } if (m_pApplication) diff --git a/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.h b/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.h index 94f2718e08..998cdc5ae1 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.h +++ b/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.h @@ -12,7 +12,7 @@ extern BOOL g_fRecycleProcessCalled; -class APPLICATION_INFO +class APPLICATION_INFO: NonCopyable { public: @@ -29,16 +29,16 @@ public: InitializeSRWLock(&m_applicationLock); } - ~APPLICATION_INFO(); + ~APPLICATION_INFO() = default; - std::wstring& - QueryApplicationInfoKey() + const std::wstring& + QueryApplicationInfoKey() const noexcept { return m_strInfoKey; } - std::wstring& - QueryConfigPath() + const std::wstring& + QueryConfigPath() const noexcept { return m_strConfigPath; } @@ -48,7 +48,7 @@ public: HRESULT GetOrCreateApplication( - IHttpContext *pHttpContext, + IHttpContext& pHttpContext, std::unique_ptr& pApplication ); diff --git a/src/AspNetCoreModuleV2/AspNetCore/applicationmanager.cpp b/src/AspNetCoreModuleV2/AspNetCore/applicationmanager.cpp index 7b9df85a43..52d9730ec1 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/applicationmanager.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/applicationmanager.cpp @@ -11,9 +11,6 @@ extern BOOL g_fInShutdown; -// The application manager is a singleton across ANCM. -APPLICATION_MANAGER* APPLICATION_MANAGER::sm_pApplicationManager = NULL; - // // Retrieves the application info from the application manager // Will create the application info if it isn't initalized diff --git a/src/AspNetCoreModuleV2/AspNetCore/applicationmanager.h b/src/AspNetCoreModuleV2/AspNetCore/applicationmanager.h index ab3fbe9746..a9fdde6a5f 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/applicationmanager.h +++ b/src/AspNetCoreModuleV2/AspNetCore/applicationmanager.h @@ -19,25 +19,6 @@ class APPLICATION_MANAGER { public: - static - APPLICATION_MANAGER* - GetInstance() - { - assert(sm_pApplicationManager); - return sm_pApplicationManager; - } - - static - VOID - Cleanup() - { - if(sm_pApplicationManager != NULL) - { - delete sm_pApplicationManager; - sm_pApplicationManager = NULL; - } - } - HRESULT GetOrCreateApplicationInfo( _In_ IHttpContext& pHttpContext, @@ -51,16 +32,7 @@ public: VOID ShutDown(); - - static HRESULT StaticInitialize(HMODULE hModule, IHttpServer& pHttpServer) - { - assert(!sm_pApplicationManager); - sm_pApplicationManager = new APPLICATION_MANAGER(hModule, pHttpServer); - return S_OK; - } - - -private: + APPLICATION_MANAGER(HMODULE hModule, IHttpServer& pHttpServer) : m_pApplicationInfoHash(NULL), m_fDebugInitialize(FALSE), @@ -70,8 +42,9 @@ private: InitializeSRWLock(&m_srwLock); } +private: + std::unordered_map> m_pApplicationInfoHash; - static APPLICATION_MANAGER *sm_pApplicationManager; SRWLOCK m_srwLock {}; BOOL m_fDebugInitialize; IHttpServer &m_pHttpServer; diff --git a/src/AspNetCoreModuleV2/AspNetCore/dllmain.cpp b/src/AspNetCoreModuleV2/AspNetCore/dllmain.cpp index b20ca03b97..1f34270aee 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/dllmain.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/dllmain.cpp @@ -13,7 +13,7 @@ DECLARE_DEBUG_PRINT_OBJECT("aspnetcorev2.dll"); -HANDLE g_hEventLog = NULL; +HANDLE g_hEventLog = nullptr; BOOL g_fRecycleProcessCalled = FALSE; BOOL g_fInShutdown = FALSE; HINSTANCE g_hServerModule; @@ -21,14 +21,14 @@ HINSTANCE g_hServerModule; VOID StaticCleanup() { - APPLICATION_MANAGER::Cleanup(); - if (g_hEventLog != NULL) + if (g_hEventLog != nullptr) { DeregisterEventSource(g_hEventLog); - g_hEventLog = NULL; + g_hEventLog = nullptr; } DebugStop(); + ALLOC_CACHE_HANDLER::StaticTerminate(); } BOOL WINAPI DllMain(HMODULE hModule, @@ -41,11 +41,14 @@ BOOL WINAPI DllMain(HMODULE hModule, switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: + + ALLOC_CACHE_HANDLER::StaticInitialize(); g_hServerModule = hModule; DisableThreadLibraryCalls(hModule); DebugInitialize(hModule); break; case DLL_PROCESS_DETACH: + // IIS can cause dll detach to occur before we receive global notifications // For example, when we switch the bitness of the worker process, // this is a bug in IIS. To try to avoid AVs, we will set a global flag @@ -85,21 +88,18 @@ HRESULT --*/ { - HRESULT hr = S_OK; - HKEY hKey; + HKEY hKey {}; BOOL fDisableANCM = FALSE; - ASPNET_CORE_PROXY_MODULE_FACTORY * pFactory = NULL; - ASPNET_CORE_GLOBAL_MODULE * pGlobalModule = NULL; UNREFERENCED_PARAMETER(dwServerVersion); if (pHttpServer->IsCommandLineLaunch()) { - g_hEventLog = RegisterEventSource(NULL, ASPNETCORE_IISEXPRESS_EVENT_PROVIDER); + g_hEventLog = RegisterEventSource(nullptr, ASPNETCORE_IISEXPRESS_EVENT_PROVIDER); } else { - g_hEventLog = RegisterEventSource(NULL, ASPNETCORE_EVENT_PROVIDER); + g_hEventLog = RegisterEventSource(nullptr, ASPNETCORE_EVENT_PROVIDER); } // check whether the feature is disabled due to security reason @@ -109,14 +109,14 @@ HRESULT KEY_READ, &hKey) == NO_ERROR) { - DWORD dwType; - DWORD dwData; + DWORD dwType = 0; + DWORD dwData = 0; DWORD cbData; cbData = sizeof(dwData); if ((RegQueryValueEx(hKey, L"DisableANCM", - NULL, + nullptr, &dwType, (LPBYTE)&dwData, &cbData) == NO_ERROR) && @@ -136,7 +136,7 @@ HRESULT ASPNETCORE_EVENT_MODULE_DISABLED_MSG); // this will return 500 error to client // as we did not register the module - goto Finished; + return S_OK; } // @@ -144,43 +144,22 @@ HRESULT // The ASPNET_CORE_PROXY_MODULE_FACTORY::Terminate method will clean any // static object initialized. // - pFactory = new ASPNET_CORE_PROXY_MODULE_FACTORY; + + auto applicationManager = std::make_shared(g_hServerModule, *pHttpServer); + auto moduleFactory = std::make_unique(applicationManager); - FINISHED_IF_FAILED(pModuleInfo->SetRequestNotifications( - pFactory, + RETURN_IF_FAILED(pModuleInfo->SetRequestNotifications( + moduleFactory.release(), RQ_EXECUTE_REQUEST_HANDLER, 0)); +; + auto pGlobalModule = std::make_unique(std::move(applicationManager)); - pFactory = NULL; - - FINISHED_IF_FAILED(APPLICATION_MANAGER::StaticInitialize(g_hServerModule, *pHttpServer)); - - pGlobalModule = NULL; - - pGlobalModule = new ASPNET_CORE_GLOBAL_MODULE(APPLICATION_MANAGER::GetInstance()); - - FINISHED_IF_FAILED(pModuleInfo->SetGlobalNotifications( - pGlobalModule, + RETURN_IF_FAILED(pModuleInfo->SetGlobalNotifications( + pGlobalModule.release(), GL_CONFIGURATION_CHANGE | // Configuration change trigers IIS application stop GL_STOP_LISTENING)); // worker process stop or recycle - - pGlobalModule = NULL; - - FINISHED_IF_FAILED(ALLOC_CACHE_HANDLER::StaticInitialize()); - -Finished: - if (pGlobalModule != NULL) - { - delete pGlobalModule; - pGlobalModule = NULL; - } - - if (pFactory != NULL) - { - pFactory->Terminate(); - pFactory = NULL; - } - - return hr; + + return S_OK; } CATCH_RETURN() diff --git a/src/AspNetCoreModuleV2/AspNetCore/globalmodule.cpp b/src/AspNetCoreModuleV2/AspNetCore/globalmodule.cpp index 755b1ffc79..abe08964cd 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/globalmodule.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/globalmodule.cpp @@ -5,10 +5,9 @@ extern BOOL g_fInShutdown; -ASPNET_CORE_GLOBAL_MODULE::ASPNET_CORE_GLOBAL_MODULE( - APPLICATION_MANAGER* pApplicationManager) +ASPNET_CORE_GLOBAL_MODULE::ASPNET_CORE_GLOBAL_MODULE(std::shared_ptr pApplicationManager) noexcept + :m_pApplicationManager(std::move(pApplicationManager)) { - m_pApplicationManager = pApplicationManager; } // @@ -30,11 +29,8 @@ ASPNET_CORE_GLOBAL_MODULE::OnGlobalStopListening( return GL_NOTIFICATION_CONTINUE; } - DBG_ASSERT(m_pApplicationManager); - // we should let application manager to shutdown all allication - // and dereference it as some requests may still reference to application manager m_pApplicationManager->ShutDown(); - m_pApplicationManager = NULL; + m_pApplicationManager = nullptr; // Return processing to the pipeline. return GL_NOTIFICATION_CONTINUE; @@ -59,13 +55,13 @@ ASPNET_CORE_GLOBAL_MODULE::OnGlobalConfigurationChange( LOG_INFOF(L"ASPNET_CORE_GLOBAL_MODULE::OnGlobalConfigurationChange '%ls'", pwszChangePath); // Test for an error. - if (NULL != pwszChangePath && + if (nullptr != pwszChangePath && _wcsicmp(pwszChangePath, L"MACHINE") != 0 && _wcsicmp(pwszChangePath, L"MACHINE/WEBROOT") != 0) { - if (m_pApplicationManager != NULL) + if (m_pApplicationManager) { - m_pApplicationManager->RecycleApplicationFromManager(pwszChangePath); + m_pApplicationManager->RecycleApplicationFromManager(pwszChangePath); } } diff --git a/src/AspNetCoreModuleV2/AspNetCore/globalmodule.h b/src/AspNetCoreModuleV2/AspNetCore/globalmodule.h index 13b6f86bea..80f047e08d 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/globalmodule.h +++ b/src/AspNetCoreModuleV2/AspNetCore/globalmodule.h @@ -5,20 +5,18 @@ #include "applicationmanager.h" -class ASPNET_CORE_GLOBAL_MODULE : public CGlobalModule +class ASPNET_CORE_GLOBAL_MODULE : NonCopyable, public CGlobalModule { public: ASPNET_CORE_GLOBAL_MODULE( - APPLICATION_MANAGER* pApplicationManager - ); + std::shared_ptr pApplicationManager + ) noexcept; - ~ASPNET_CORE_GLOBAL_MODULE() - { - } + virtual ~ASPNET_CORE_GLOBAL_MODULE() = default; - VOID Terminate() + VOID Terminate() override { LOG_INFO(L"ASPNET_CORE_GLOBAL_MODULE::Terminate"); // Remove the class from memory. @@ -28,13 +26,13 @@ public: GLOBAL_NOTIFICATION_STATUS OnGlobalStopListening( _In_ IGlobalStopListeningProvider * pProvider - ); + ) override; GLOBAL_NOTIFICATION_STATUS OnGlobalConfigurationChange( _In_ IGlobalConfigurationChangeProvider * pProvider - ); + ) override; private: - APPLICATION_MANAGER * m_pApplicationManager; + std::shared_ptr m_pApplicationManager; }; diff --git a/src/AspNetCoreModuleV2/AspNetCore/proxymodule.cpp b/src/AspNetCoreModuleV2/AspNetCore/proxymodule.cpp index b4ed0fbaad..c93c7c7602 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/proxymodule.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/proxymodule.cpp @@ -5,31 +5,40 @@ #include "applicationmanager.h" #include "applicationinfo.h" -#include "acache.h" #include "exceptions.h" extern BOOL g_fInShutdown; __override + +ASPNET_CORE_PROXY_MODULE_FACTORY::ASPNET_CORE_PROXY_MODULE_FACTORY(std::shared_ptr applicationManager) noexcept + :m_pApplicationManager(std::move(applicationManager)) +{ +} + HRESULT ASPNET_CORE_PROXY_MODULE_FACTORY::GetHttpModule( CHttpModule ** ppModule, IModuleAllocator * pAllocator ) { - try + + #pragma warning( push ) + #pragma warning ( disable : 26409 ) // Disable "Avoid using new" + *ppModule = new (pAllocator) ASPNET_CORE_PROXY_MODULE(m_pApplicationManager); + #pragma warning( push ) + if (*ppModule == nullptr) { - *ppModule = THROW_IF_NULL_ALLOC(new (pAllocator) ASPNET_CORE_PROXY_MODULE());; - return S_OK; + return E_OUTOFMEMORY; } - CATCH_RETURN(); + return S_OK; } __override VOID ASPNET_CORE_PROXY_MODULE_FACTORY::Terminate( VOID -) +) noexcept /*++ Routine description: @@ -46,12 +55,13 @@ Return value: --*/ { - ALLOC_CACHE_HANDLER::StaticTerminate(); delete this; } -ASPNET_CORE_PROXY_MODULE::ASPNET_CORE_PROXY_MODULE( -) : m_pApplicationInfo(nullptr), m_pHandler(nullptr) +ASPNET_CORE_PROXY_MODULE::ASPNET_CORE_PROXY_MODULE(std::shared_ptr applicationManager) noexcept + : m_pApplicationManager(std::move(applicationManager)), + m_pApplicationInfo(nullptr), + m_pHandler(nullptr) { } @@ -64,6 +74,7 @@ ASPNET_CORE_PROXY_MODULE::OnExecuteRequestHandler( { HRESULT hr = S_OK; REQUEST_NOTIFICATION_STATUS retVal = RQ_NOTIFICATION_CONTINUE; + try { @@ -72,14 +83,12 @@ ASPNET_CORE_PROXY_MODULE::OnExecuteRequestHandler( FINISHED(HRESULT_FROM_WIN32(ERROR_SERVER_SHUTDOWN_IN_PROGRESS)); } - auto pApplicationManager = APPLICATION_MANAGER::GetInstance(); - - FINISHED_IF_FAILED(pApplicationManager->GetOrCreateApplicationInfo( + FINISHED_IF_FAILED(m_pApplicationManager->GetOrCreateApplicationInfo( *pHttpContext, m_pApplicationInfo)); std::unique_ptr pApplication; - FINISHED_IF_FAILED(m_pApplicationInfo->GetOrCreateApplication(pHttpContext, pApplication)); + FINISHED_IF_FAILED(m_pApplicationInfo->GetOrCreateApplication(*pHttpContext, pApplication)); IREQUEST_HANDLER* pHandler; // Create RequestHandler and process the request @@ -94,7 +103,7 @@ ASPNET_CORE_PROXY_MODULE::OnExecuteRequestHandler( } Finished: - if (LOG_IF_FAILED(hr)) + if (FAILED(LOG_IF_FAILED(hr))) { retVal = RQ_NOTIFICATION_FINISH_REQUEST; if (hr == HRESULT_FROM_WIN32(ERROR_SERVER_SHUTDOWN_IN_PROGRESS)) diff --git a/src/AspNetCoreModuleV2/AspNetCore/proxymodule.h b/src/AspNetCoreModuleV2/AspNetCore/proxymodule.h index 06e333d595..7c67712bab 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/proxymodule.h +++ b/src/AspNetCoreModuleV2/AspNetCore/proxymodule.h @@ -6,14 +6,15 @@ #include #include "applicationinfo.h" #include "irequesthandler.h" +#include "applicationmanager.h" extern HTTP_MODULE_ID g_pModuleId; -class ASPNET_CORE_PROXY_MODULE : public CHttpModule +class ASPNET_CORE_PROXY_MODULE : NonCopyable, public CHttpModule { public: - ASPNET_CORE_PROXY_MODULE(); + ASPNET_CORE_PROXY_MODULE(std::shared_ptr applicationManager) noexcept; ~ASPNET_CORE_PROXY_MODULE() = default; @@ -33,7 +34,7 @@ class ASPNET_CORE_PROXY_MODULE : public CHttpModule OnExecuteRequestHandler( IHttpContext * pHttpContext, IHttpEventProvider * pProvider - ); + ) override; __override REQUEST_NOTIFICATION_STATUS @@ -43,22 +44,29 @@ class ASPNET_CORE_PROXY_MODULE : public CHttpModule BOOL fPostNotification, IHttpEventProvider * pProvider, IHttpCompletionInfo * pCompletionInfo - ); + ) override; private: + std::shared_ptr m_pApplicationManager; std::shared_ptr m_pApplicationInfo; - std::unique_ptr m_pHandler; + std::unique_ptr m_pHandler; }; -class ASPNET_CORE_PROXY_MODULE_FACTORY : public IHttpModuleFactory +class ASPNET_CORE_PROXY_MODULE_FACTORY : NonCopyable, public IHttpModuleFactory { public: + ASPNET_CORE_PROXY_MODULE_FACTORY(std::shared_ptr applicationManager) noexcept; + virtual ~ASPNET_CORE_PROXY_MODULE_FACTORY() = default; + HRESULT GetHttpModule( CHttpModule ** ppModule, IModuleAllocator * pAllocator - ); + ) override; VOID - Terminate(); + Terminate() noexcept override; + + private: + std::shared_ptr m_pApplicationManager; }; diff --git a/src/AspNetCoreModuleV2/CommonLib/EventLog.cpp b/src/AspNetCoreModuleV2/CommonLib/EventLog.cpp index a8b32849ff..c3a3608820 100644 --- a/src/AspNetCoreModuleV2/CommonLib/EventLog.cpp +++ b/src/AspNetCoreModuleV2/CommonLib/EventLog.cpp @@ -50,7 +50,7 @@ EventLog::LogEventF( _In_ WORD dwEventInfoType, _In_ DWORD dwEventId, _In_ LPCWSTR pstrMsg, - va_list argsList + _In_ va_list argsList ) { STACK_STRU ( strEventMsg, 256 ); diff --git a/src/AspNetCoreModuleV2/CommonLib/EventLog.h b/src/AspNetCoreModuleV2/CommonLib/EventLog.h index cdc330300f..fa2cde1947 100644 --- a/src/AspNetCoreModuleV2/CommonLib/EventLog.h +++ b/src/AspNetCoreModuleV2/CommonLib/EventLog.h @@ -5,6 +5,18 @@ #include "resources.h" +#define _va_start(ap, x) \ + __pragma(warning(push)) \ + __pragma(warning(disable:26481 26492)) /*Don't use pointer arithmetic. Don't use const_cast to cast away const.*/ \ + va_start(ap, x) \ + __pragma(warning(pop)) + +#define _va_end(args) \ + __pragma(warning(push)) \ + __pragma(warning(disable:26477)) /*Use 'nullptr' rather than 0 or NULL*/ \ + va_end(args) \ + __pragma(warning(pop)) + class EventLog { public: @@ -16,9 +28,9 @@ public: ...) { va_list args; - va_start(args, pstrMsg); + _va_start(args, pstrMsg); LogEventF(EVENTLOG_ERROR_TYPE, dwEventId, pstrMsg, args); - va_end(args); + _va_end(args); } static @@ -29,9 +41,9 @@ public: ...) { va_list args; - va_start(args, pstrMsg); + _va_start(args, pstrMsg); LogEventF(EVENTLOG_INFORMATION_TYPE, dwEventId, pstrMsg, args); - va_end(args); + _va_end(args); } static @@ -42,9 +54,9 @@ public: ...) { va_list args; - va_start(args, pstrMsg); + _va_start(args, pstrMsg); LogEventF(EVENTLOG_WARNING_TYPE, dwEventId, pstrMsg, args); - va_end(args); + _va_end(args); } private: diff --git a/src/AspNetCoreModuleV2/CommonLib/FileOutputManager.cpp b/src/AspNetCoreModuleV2/CommonLib/FileOutputManager.cpp index 69cc0fe76a..fb95017af8 100644 --- a/src/AspNetCoreModuleV2/CommonLib/FileOutputManager.cpp +++ b/src/AspNetCoreModuleV2/CommonLib/FileOutputManager.cpp @@ -174,7 +174,7 @@ FileOutputManager::Stop() if (li.LowPart == 0 || li.HighPart > 0) { - RETURN_IF_FAILED(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); } dwFilePointer = SetFilePointer(m_hLogFileHandle, 0, NULL, FILE_BEGIN); diff --git a/src/AspNetCoreModuleV2/CommonLib/HandleWrapper.h b/src/AspNetCoreModuleV2/CommonLib/HandleWrapper.h index d3afa64551..56da4ae035 100644 --- a/src/AspNetCoreModuleV2/CommonLib/HandleWrapper.h +++ b/src/AspNetCoreModuleV2/CommonLib/HandleWrapper.h @@ -10,37 +10,41 @@ struct InvalidHandleTraits { using HandleType = HANDLE; static const HANDLE DefaultHandle; - static void Close(HANDLE handle) { CloseHandle(handle); } + static void Close(HANDLE handle) noexcept { CloseHandle(handle); } }; struct NullHandleTraits { using HandleType = HANDLE; - static constexpr HANDLE DefaultHandle = NULL; - static void Close(HANDLE handle) { CloseHandle(handle); } + static constexpr HANDLE DefaultHandle = nullptr; + static void Close(HANDLE handle) noexcept { CloseHandle(handle); } }; struct FindFileHandleTraits { using HandleType = HANDLE; static const HANDLE DefaultHandle; - static void Close(HANDLE handle) { FindClose(handle); } + static void Close(HANDLE handle) noexcept { FindClose(handle); } }; struct ModuleHandleTraits { using HandleType = HMODULE; - static constexpr HMODULE DefaultHandle = NULL; - static void Close(HMODULE handle) { FreeModule(handle); } + static constexpr HMODULE DefaultHandle = nullptr; + static void Close(HMODULE handle) noexcept { FreeModule(handle); } }; +// Code analysis doesn't like nullptr usages via traits +#pragma warning( push ) +#pragma warning ( disable : 26477 ) // disable Use 'nullptr' rather than 0 or NULL (es.47). + template class HandleWrapper { public: using HandleType = typename traits::HandleType; - HandleWrapper(HandleType handle = traits::DefaultHandle) : m_handle(handle) { } + HandleWrapper(HandleType handle = traits::DefaultHandle) noexcept : m_handle(handle) { } ~HandleWrapper() { if (m_handle != traits::DefaultHandle) @@ -49,15 +53,15 @@ public: } } - operator HandleType() { return m_handle; } - HandleWrapper& operator =(HandleType value) + operator HandleType() noexcept { return m_handle; } + HandleWrapper& operator =(HandleType value) noexcept { DBG_ASSERT(m_handle == traits::DefaultHandle); m_handle = value; return *this; } - HandleType* operator&() { return &m_handle; } + HandleType* operator&() noexcept { return &m_handle; } HandleType release() noexcept { @@ -69,3 +73,5 @@ public: private: HandleType m_handle; }; + +#pragma warning( pop ) diff --git a/src/AspNetCoreModuleV2/CommonLib/IOutputManager.h b/src/AspNetCoreModuleV2/CommonLib/IOutputManager.h index 6b733dd0e6..fec85cea96 100644 --- a/src/AspNetCoreModuleV2/CommonLib/IOutputManager.h +++ b/src/AspNetCoreModuleV2/CommonLib/IOutputManager.h @@ -14,7 +14,7 @@ public: Start() = 0; virtual - ~IOutputManager() {}; + ~IOutputManager() = default; virtual bool diff --git a/src/AspNetCoreModuleV2/CommonLib/ModuleHelpers.h b/src/AspNetCoreModuleV2/CommonLib/ModuleHelpers.h index 0ef9a7662d..cab86d76ea 100644 --- a/src/AspNetCoreModuleV2/CommonLib/ModuleHelpers.h +++ b/src/AspNetCoreModuleV2/CommonLib/ModuleHelpers.h @@ -14,7 +14,26 @@ public: void IncrementCurrentModuleRefCount(HandleWrapper &handle) { WCHAR path[MAX_PATH]; - THROW_LAST_ERROR_IF(!GetModuleFileName(g_hModule, path, sizeof(path))); + +#pragma warning( push ) +#pragma warning ( disable : 26485 ) // Calling WinAPI causes expected array to pointer decay + + THROW_LAST_ERROR_IF(!GetModuleFileName(g_hModule, path, MAX_PATH)); THROW_LAST_ERROR_IF(!GetModuleHandleEx(0, path, &handle)); + +#pragma warning( pop ) + } + + template + static + Func GetKnownProcAddress(HMODULE hModule, LPCSTR lpProcName) { + +#pragma warning( push ) +#pragma warning ( disable : 26490 ) // Disable Don't use reinterpret_cast + auto proc = reinterpret_cast(GetProcAddress(hModule, lpProcName)); +#pragma warning( pop ) + + THROW_LAST_ERROR_IF (!proc); + return proc; } }; diff --git a/src/AspNetCoreModuleV2/CommonLib/NonCopyable.h b/src/AspNetCoreModuleV2/CommonLib/NonCopyable.h index 8dcb282411..11f73903fa 100644 --- a/src/AspNetCoreModuleV2/CommonLib/NonCopyable.h +++ b/src/AspNetCoreModuleV2/CommonLib/NonCopyable.h @@ -6,6 +6,6 @@ class NonCopyable { public: NonCopyable() = default; - NonCopyable(const NonCopyable&) = default; - NonCopyable& operator=(const NonCopyable&) = default; + NonCopyable(const NonCopyable&) = delete; + NonCopyable& operator=(const NonCopyable&) = delete; }; diff --git a/src/AspNetCoreModuleV2/CommonLib/ResultException.h b/src/AspNetCoreModuleV2/CommonLib/ResultException.h new file mode 100644 index 0000000000..e6cb8b4b81 --- /dev/null +++ b/src/AspNetCoreModuleV2/CommonLib/ResultException.h @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +#pragma once + +class ResultException: public std::runtime_error +{ +public: + ResultException(HRESULT hr, LOCATION_ARGUMENTS_ONLY) : + runtime_error(format("HRESULT 0x%x returned at " LOCATION_FORMAT, hr, LOCATION_CALL_ONLY)), + m_hr(hr) + { + } + + HRESULT GetResult() const noexcept { return m_hr; } + +private: + HRESULT m_hr; +}; diff --git a/src/AspNetCoreModuleV2/CommonLib/StdWrapper.cpp b/src/AspNetCoreModuleV2/CommonLib/StdWrapper.cpp index dffaa491c5..432e48a163 100644 --- a/src/AspNetCoreModuleV2/CommonLib/StdWrapper.cpp +++ b/src/AspNetCoreModuleV2/CommonLib/StdWrapper.cpp @@ -78,14 +78,14 @@ StdWrapper::StartRedirection() if (fileDescriptor == -1) { - RETURN_IF_FAILED(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); } m_redirectedFile = _fdopen(fileDescriptor, "w"); if (m_redirectedFile == nullptr) { - RETURN_IF_FAILED(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); } // Set stdout/stderr to the newly created file. @@ -93,13 +93,13 @@ StdWrapper::StartRedirection() if (dup2Result != 0) { - RETURN_IF_FAILED(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); } // Removes buffering from the output if (setvbuf(m_stdStream, nullptr, _IONBF, 0) != 0) { - RETURN_IF_FAILED(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); } return S_OK; @@ -117,7 +117,7 @@ StdWrapper::StopRedirection() const FILE * file = _fdopen(m_previousFileDescriptor, "w"); if (file == nullptr) { - RETURN_IF_FAILED(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); } RETURN_LAST_ERROR_IF(!SetStdHandle(m_stdHandleNumber, reinterpret_cast(_get_osfhandle(m_previousFileDescriptor)))); @@ -131,17 +131,17 @@ StdWrapper::StopRedirection() const const auto dup2Result = _dup2(_fileno(file), _fileno(m_stdStream)); if (dup2Result != 0) { - RETURN_IF_FAILED(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); } if (setvbuf(m_stdStream, nullptr, _IONBF, 0) != 0) { - RETURN_IF_FAILED(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); } if (fclose(m_redirectedFile) != 0) { - RETURN_IF_FAILED(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); + RETURN_HR(HRESULT_FROM_WIN32(ERROR_FILE_INVALID)); } return S_OK; diff --git a/src/AspNetCoreModuleV2/CommonLib/StringHelpers.h b/src/AspNetCoreModuleV2/CommonLib/StringHelpers.h index 957f5bc3d6..e6cda03ff7 100644 --- a/src/AspNetCoreModuleV2/CommonLib/StringHelpers.h +++ b/src/AspNetCoreModuleV2/CommonLib/StringHelpers.h @@ -15,19 +15,33 @@ template [[nodiscard]] std::wstring format(const std::wstring& format, Args ... args) { - const size_t size = swprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra char for '\0' - std::unique_ptr formattedBuffer(new wchar_t[size]); - swprintf(formattedBuffer.get(), size, format.c_str(), args ... ); - return std::wstring(formattedBuffer.get(), formattedBuffer.get() + size - 1); + std::wstring result; + if (!format.empty()) + { + const size_t size = swprintf(nullptr, 0, format.c_str(), args ...); // Extra char for '\0' + result.resize(size + 1); + if (swprintf(result.data(), result.size(), format.c_str(), args ... ) == -1) + { + throw std::system_error(std::error_code(errno, std::system_category())); + } + } + return result; } template [[nodiscard]] std::string format(const std::string& format, Args ... args) { - const size_t size = snprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra char for '\0' - std::unique_ptr formattedBuffer(new char[size]); - snprintf(formattedBuffer.get(), size, format.c_str(), args ... ); - return std::string(formattedBuffer.get(), formattedBuffer.get() + size - 1); + std::string result; + if (!format.empty()) + { + const size_t size = snprintf(nullptr, 0, format.c_str(), args ...); // Extra char for '\0' + result.resize(size + 1); + if (snprintf(result.data(), result.size(), format.c_str(), args ... ) == -1) + { + throw std::system_error(std::error_code(errno, std::system_category())); + } + } + return result; } diff --git a/src/AspNetCoreModuleV2/CommonLib/WebConfigConfigurationSource.h b/src/AspNetCoreModuleV2/CommonLib/WebConfigConfigurationSource.h index ce8dbcdc50..d0c866096b 100644 --- a/src/AspNetCoreModuleV2/CommonLib/WebConfigConfigurationSource.h +++ b/src/AspNetCoreModuleV2/CommonLib/WebConfigConfigurationSource.h @@ -9,7 +9,7 @@ class WebConfigConfigurationSource: public ConfigurationSource { public: - WebConfigConfigurationSource(IAppHostAdminManager *pAdminManager, IHttpApplication &pHttpApplication) + WebConfigConfigurationSource(IAppHostAdminManager *pAdminManager, const IHttpApplication &pHttpApplication) noexcept : m_manager(pAdminManager), m_application(pHttpApplication) { @@ -19,5 +19,5 @@ public: private: CComPtr m_manager; - IHttpApplication &m_application; + const IHttpApplication &m_application; }; diff --git a/src/AspNetCoreModuleV2/CommonLib/application.h b/src/AspNetCoreModuleV2/CommonLib/application.h index e99159d324..c3d8eeb898 100644 --- a/src/AspNetCoreModuleV2/CommonLib/application.h +++ b/src/AspNetCoreModuleV2/CommonLib/application.h @@ -58,7 +58,7 @@ public: } VOID - ReferenceApplication() override + ReferenceApplication() noexcept override { DBG_ASSERT(m_cRefs > 0); @@ -66,7 +66,7 @@ public: } VOID - DereferenceApplication() override + DereferenceApplication() noexcept override { DBG_ASSERT(m_cRefs > 0); @@ -77,25 +77,25 @@ public: } const std::wstring& - QueryApplicationId() const + QueryApplicationId() const noexcept { return m_applicationId; } const std::wstring& - QueryApplicationPhysicalPath() const + QueryApplicationPhysicalPath() const noexcept { return m_applicationPhysicalPath; } const std::wstring& - QueryApplicationVirtualPath() const + QueryApplicationVirtualPath() const noexcept { return m_applicationVirtualPath; } const std::wstring& - QueryConfigPath() const + QueryConfigPath() const noexcept { return m_applicationConfigPath; } diff --git a/src/AspNetCoreModuleV2/CommonLib/exceptions.h b/src/AspNetCoreModuleV2/CommonLib/exceptions.h index 0bf30d1bcc..109f76ce87 100644 --- a/src/AspNetCoreModuleV2/CommonLib/exceptions.h +++ b/src/AspNetCoreModuleV2/CommonLib/exceptions.h @@ -31,20 +31,36 @@ #define OBSERVE_CAUGHT_EXCEPTION() CaughtExceptionHResult(LOCATION_INFO); #define RETURN_CAUGHT_EXCEPTION() return CaughtExceptionHResult(LOCATION_INFO); -#define RETURN_HR(hr) do { HRESULT __hrRet = hr; if (FAILED(__hrRet)) { LogHResultFailed(LOCATION_INFO, __hrRet); } return __hrRet; } while (0, 0) +#define _CHECK_FAILED(expr) __pragma(warning(push)) \ + __pragma(warning(disable:4127)) /*disable condition is const warning*/ \ + FAILED(expr) \ + __pragma(warning(pop)) + +#define _HR_RET(hr) __pragma(warning(push)) \ + __pragma(warning(disable:26498)) /*disable constexpr warning */ \ + const HRESULT __hrRet = hr; \ + __pragma(warning(pop)) + +#define RETURN_HR(hr) do { _HR_RET(hr); if (_CHECK_FAILED(__hrRet)) { LogHResultFailed(LOCATION_INFO, __hrRet); } return __hrRet; } while (0, 0) #define RETURN_LAST_ERROR() do { return LogLastError(LOCATION_INFO); } while (0, 0) -#define RETURN_IF_FAILED(hr) do { HRESULT __hrRet = hr; if (FAILED(__hrRet)) { LogHResultFailed(LOCATION_INFO, __hrRet); return __hrRet; }} while (0, 0) +#define RETURN_IF_FAILED(hr) do { _HR_RET(hr); if (FAILED(__hrRet)) { LogHResultFailed(LOCATION_INFO, __hrRet); return __hrRet; }} while (0, 0) #define RETURN_LAST_ERROR_IF(condition) do { if (condition) { return LogLastError(LOCATION_INFO); }} while (0, 0) #define RETURN_LAST_ERROR_IF_NULL(ptr) do { if ((ptr) == nullptr) { return LogLastError(LOCATION_INFO); }} while (0, 0) -#define FINISHED(hrr) do { HRESULT __hrRet = hrr; LogHResultFailed(LOCATION_INFO, __hrRet); hr = __hrRet; goto Finished; } while (0, 0) -#define FINISHED_IF_FAILED(hrr) do { HRESULT __hrRet = hrr; if (FAILED(__hrRet)) { LogHResultFailed(LOCATION_INFO, __hrRet); hr = __hrRet; goto Finished; }} while (0, 0) -#define FINISHED_IF_NULL_ALLOC(ptr) do { if ((ptr) == nullptr) { hr = LogHResultFailed(LOCATION_INFO, E_OUTOFMEMORY); goto Finished; }} while (0, 0) -#define FINISHED_LAST_ERROR_IF(condition) do { if (condition) { hr = LogLastError(LOCATION_INFO); goto Finished; }} while (0, 0) -#define FINISHED_LAST_ERROR_IF_NULL(ptr) do { if ((ptr) == nullptr) { hr = LogLastError(LOCATION_INFO); goto Finished; }} while (0, 0) +#define _GOTO_FINISHED() __pragma(warning(push)) \ + __pragma(warning(disable:26438)) /*disable avoid goto warning*/ \ + goto Finished \ + __pragma(warning(pop)) + + +#define FINISHED(hrr) do { _HR_RET(hrr); if (_CHECK_FAILED(__hrRet)) { LogHResultFailed(LOCATION_INFO, __hrRet); } hr = __hrRet; _GOTO_FINISHED(); } while (0, 0) +#define FINISHED_IF_FAILED(hrr) do { _HR_RET(hrr); if (FAILED(__hrRet)) { LogHResultFailed(LOCATION_INFO, __hrRet); hr = __hrRet; _GOTO_FINISHED(); }} while (0, 0) +#define FINISHED_IF_NULL_ALLOC(ptr) do { if ((ptr) == nullptr) { hr = LogHResultFailed(LOCATION_INFO, E_OUTOFMEMORY); _GOTO_FINISHED(); }} while (0, 0) +#define FINISHED_LAST_ERROR_IF(condition) do { if (condition) { hr = LogLastError(LOCATION_INFO); _GOTO_FINISHED(); }} while (0, 0) +#define FINISHED_LAST_ERROR_IF_NULL(ptr) do { if ((ptr) == nullptr) { hr = LogLastError(LOCATION_INFO); _GOTO_FINISHED(); }} while (0, 0) #define THROW_LAST_ERROR() do { ThrowResultException(LOCATION_INFO, LogLastError(LOCATION_INFO)); } while (0, 0) -#define THROW_IF_FAILED(hr) do { HRESULT __hrRet = hr; if (FAILED(__hrRet)) { ThrowResultException(LOCATION_INFO, __hrRet); }} while (0, 0) +#define THROW_IF_FAILED(hr) do { _HR_RET(hr); if (FAILED(__hrRet)) { ThrowResultException(LOCATION_INFO, __hrRet); }} while (0, 0) #define THROW_LAST_ERROR_IF(condition) do { if (condition) { ThrowResultException(LOCATION_INFO, LogLastError(LOCATION_INFO)); }} while (0, 0) #define THROW_LAST_ERROR_IF_NULL(ptr) do { if ((ptr) == nullptr) { ThrowResultException(LOCATION_INFO, LogLastError(LOCATION_INFO)); }} while (0, 0) @@ -57,21 +73,24 @@ #define SUCCEEDED_LOG(hr) SUCCEEDED(LOG_IF_FAILED(hr)) #define FAILED_LOG(hr) FAILED(LOG_IF_FAILED(hr)) - class ResultException: public std::runtime_error { public: - explicit ResultException(HRESULT hr, LOCATION_ARGUMENTS_ONLY) : + ResultException(HRESULT hr, LOCATION_ARGUMENTS_ONLY) : runtime_error(format("HRESULT 0x%x returned at " LOCATION_FORMAT, hr, LOCATION_CALL_ONLY)), m_hr(hr) { } - HRESULT GetResult() const { return m_hr; } + HRESULT GetResult() const noexcept { return m_hr; } private: - HRESULT m_hr; + +#pragma warning( push ) +#pragma warning ( disable : 26495 ) // bug in CA: m_hr is reported as uninitialized + const HRESULT m_hr = S_OK; }; +#pragma warning( pop ) __declspec(noinline) inline VOID ReportUntypedException(LOCATION_ARGUMENTS_ONLY) { @@ -98,7 +117,7 @@ private: return condition; } - __declspec(noinline) inline VOID ReportException(LOCATION_ARGUMENTS std::exception& exception) + __declspec(noinline) inline VOID ReportException(LOCATION_ARGUMENTS const std::exception& exception) { DebugPrintf(ASPNETCORE_DEBUG_FLAG_ERROR, "Exception '%s' caught at " LOCATION_FORMAT, exception.what(), LOCATION_CALL_ONLY); } @@ -122,12 +141,12 @@ __declspec(noinline) inline HRESULT CaughtExceptionHResult(LOCATION_ARGUMENTS_ON { return E_OUTOFMEMORY; } - catch (ResultException& exception) + catch (const ResultException& exception) { ReportException(LOCATION_CALL exception); return exception.GetResult(); } - catch (std::exception& exception) + catch (const std::exception& exception) { ReportException(LOCATION_CALL exception); return HRESULT_FROM_WIN32(ERROR_UNHANDLED_EXCEPTION); @@ -154,7 +173,7 @@ template auto Throw_IfNullAlloc(PointerT pointer) } return pointer; } -__declspec(noinline) inline std::wstring GetUnexpectedExceptionMessage(std::runtime_error& ex) +__declspec(noinline) inline std::wstring GetUnexpectedExceptionMessage(const std::runtime_error& ex) { return format(L"Unexpected exception: %S", ex.what()); } diff --git a/src/AspNetCoreModuleV2/CommonLib/fx_ver.h b/src/AspNetCoreModuleV2/CommonLib/fx_ver.h index 2740fa37ee..723a0da360 100644 --- a/src/AspNetCoreModuleV2/CommonLib/fx_ver.h +++ b/src/AspNetCoreModuleV2/CommonLib/fx_ver.h @@ -13,15 +13,15 @@ struct fx_ver_t fx_ver_t(int major, int minor, int patch, const std::wstring& pre); fx_ver_t(int major, int minor, int patch, const std::wstring& pre, const std::wstring& build); - int get_major() const { return m_major; } - int get_minor() const { return m_minor; } - int get_patch() const { return m_patch; } + int get_major() const noexcept { return m_major; } + int get_minor() const noexcept { return m_minor; } + int get_patch() const noexcept { return m_patch; } - void set_major(int m) { m_major = m; } - void set_minor(int m) { m_minor = m; } - void set_patch(int p) { m_patch = p; } + void set_major(int m) noexcept { m_major = m; } + void set_minor(int m) noexcept { m_minor = m; } + void set_patch(int p) noexcept { m_patch = p; } - bool is_prerelease() const { return !m_pre.empty(); } + bool is_prerelease() const noexcept { return !m_pre.empty(); } std::wstring as_str() const; diff --git a/src/AspNetCoreModuleV2/CommonLib/hostfxroptions.h b/src/AspNetCoreModuleV2/CommonLib/hostfxroptions.h index 8c42d08c37..243cc53ae7 100644 --- a/src/AspNetCoreModuleV2/CommonLib/hostfxroptions.h +++ b/src/AspNetCoreModuleV2/CommonLib/hostfxroptions.h @@ -17,7 +17,7 @@ public: std::filesystem::path dotnetExeLocation, std::filesystem::path hostFxrLocation, std::vector arguments - ) + ) noexcept : m_dotnetExeLocation(std::move(dotnetExeLocation)), m_hostFxrLocation(std::move(hostFxrLocation)), m_arguments(std::move(arguments)) @@ -27,7 +27,7 @@ public: GetArguments(DWORD &hostfxrArgc, std::unique_ptr &hostfxrArgv) const { hostfxrArgc = static_cast(m_arguments.size()); - hostfxrArgv = std::unique_ptr(new PCWSTR[hostfxrArgc]); + hostfxrArgv = std::make_unique(hostfxrArgc); for (DWORD i = 0; i < hostfxrArgc; ++i) { hostfxrArgv[i] = m_arguments[i].c_str(); @@ -35,13 +35,13 @@ public: } const std::filesystem::path& - GetHostFxrLocation() const + GetHostFxrLocation() const noexcept { return m_hostFxrLocation; } const std::filesystem::path& - GetDotnetExeLocation() const + GetDotnetExeLocation() const noexcept { return m_dotnetExeLocation; } diff --git a/src/AspNetCoreModuleV2/CommonLib/iapplication.h b/src/AspNetCoreModuleV2/CommonLib/iapplication.h index 222230c672..7c205ed68c 100644 --- a/src/AspNetCoreModuleV2/CommonLib/iapplication.h +++ b/src/AspNetCoreModuleV2/CommonLib/iapplication.h @@ -44,7 +44,7 @@ public: HRESULT CreateHandler( _In_ IHttpContext *pHttpContext, - _Out_ IREQUEST_HANDLER **pRequestHandler) = 0; + _Outptr_ IREQUEST_HANDLER **pRequestHandler) = 0; }; struct IAPPLICATION_DELETER diff --git a/src/AspNetCoreModuleV2/CommonLib/requesthandler.h b/src/AspNetCoreModuleV2/CommonLib/requesthandler.h index ea4692f506..7de54e4c77 100644 --- a/src/AspNetCoreModuleV2/CommonLib/requesthandler.h +++ b/src/AspNetCoreModuleV2/CommonLib/requesthandler.h @@ -14,13 +14,13 @@ class REQUEST_HANDLER: public virtual IREQUEST_HANDLER public: VOID - ReferenceRequestHandler() override + ReferenceRequestHandler() noexcept override { InterlockedIncrement(&m_cRefs); } VOID - DereferenceRequestHandler() override + DereferenceRequestHandler() noexcept override { DBG_ASSERT(m_cRefs != 0); diff --git a/src/AspNetCoreModuleV2/DefaultRules.ruleset b/src/AspNetCoreModuleV2/DefaultRules.ruleset new file mode 100644 index 0000000000..1c2bbdaeaf --- /dev/null +++ b/src/AspNetCoreModuleV2/DefaultRules.ruleset @@ -0,0 +1,432 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AspNetCoreModuleV2/IISLib/acache.cpp b/src/AspNetCoreModuleV2/IISLib/acache.cpp index d68813edbc..5f2125134e 100644 --- a/src/AspNetCoreModuleV2/IISLib/acache.cpp +++ b/src/AspNetCoreModuleV2/IISLib/acache.cpp @@ -3,6 +3,9 @@ #include "precomp.h" +#pragma warning( push ) +#pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS ) + LONG ALLOC_CACHE_HANDLER::sm_nFillPattern = 0xACA50000; HANDLE ALLOC_CACHE_HANDLER::sm_hHeap; @@ -440,4 +443,6 @@ Finished: } return fRet; -} \ No newline at end of file +} + +#pragma warning( pop ) diff --git a/src/AspNetCoreModuleV2/IISLib/buffer.h b/src/AspNetCoreModuleV2/IISLib/buffer.h index 1d68155387..385b73d717 100644 --- a/src/AspNetCoreModuleV2/IISLib/buffer.h +++ b/src/AspNetCoreModuleV2/IISLib/buffer.h @@ -4,7 +4,10 @@ #pragma once #include +#include +#pragma warning( push ) +#pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS ) // // BUFFER_T class shouldn't be used directly. Use BUFFER specialization class instead. @@ -269,3 +272,5 @@ C_ASSERT( sizeof(VOID*) <= sizeof(ULONGLONG) ); #define INLINE_BUFFER_INIT( _name ) \ _name( (BYTE*)__aqw##_name, sizeof( __aqw##_name ) ) + +#pragma warning( pop ) diff --git a/src/AspNetCoreModuleV2/IISLib/multisz.h b/src/AspNetCoreModuleV2/IISLib/multisz.h index f65c151d4f..9473f52033 100644 --- a/src/AspNetCoreModuleV2/IISLib/multisz.h +++ b/src/AspNetCoreModuleV2/IISLib/multisz.h @@ -6,6 +6,10 @@ #include "stringu.h" #include "ntassert.h" +#include + +#pragma warning( push ) +#pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS ) /*++ class MULTISZ: @@ -221,5 +225,6 @@ SplitCommaDelimitedString( MULTISZ * pmszList ); -#endif // !_MULTISZ_HXX_ +#pragma warning( pop ) +#endif // !_MULTISZ_HXX_ diff --git a/src/AspNetCoreModuleV2/IISLib/percpu.h b/src/AspNetCoreModuleV2/IISLib/percpu.h index 5d3c563935..07828830d7 100644 --- a/src/AspNetCoreModuleV2/IISLib/percpu.h +++ b/src/AspNetCoreModuleV2/IISLib/percpu.h @@ -3,6 +3,9 @@ #pragma once +#pragma warning( push ) +#pragma warning ( disable : 26451 ) + template class PER_CPU { @@ -302,4 +305,6 @@ Return: *pCacheLineSize = SYSTEM_CACHE_ALIGNMENT_SIZE; return S_OK; -} \ No newline at end of file +} + +#pragma warning( pop ) diff --git a/src/AspNetCoreModuleV2/IISLib/stringa.h b/src/AspNetCoreModuleV2/IISLib/stringa.h index 39737f4a69..94ace540f6 100644 --- a/src/AspNetCoreModuleV2/IISLib/stringa.h +++ b/src/AspNetCoreModuleV2/IISLib/stringa.h @@ -7,6 +7,10 @@ #include "macros.h" #include + +#pragma warning( push ) +#pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS ) + class STRA { @@ -513,3 +517,5 @@ CHAR* InitHelper(__out CHAR (&psz)[size]) STRA name; #define INLINE_STRA_INIT(name) name(InitHelper(__ach##name), sizeof(__ach##name)) + +#pragma warning( pop ) diff --git a/src/AspNetCoreModuleV2/IISLib/stringu.cpp b/src/AspNetCoreModuleV2/IISLib/stringu.cpp index 15da79a7fe..74f8595482 100644 --- a/src/AspNetCoreModuleV2/IISLib/stringu.cpp +++ b/src/AspNetCoreModuleV2/IISLib/stringu.cpp @@ -1,10 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -#pragma warning (disable : 4267) #include "precomp.h" +#pragma warning( push ) +#pragma warning ( disable : 4267 ALL_CODE_ANALYSIS_WARNINGS ) + STRU::STRU( VOID ) : m_cchLen( 0 ) @@ -1199,25 +1201,17 @@ STRU::ExpandEnvironmentVariables( __out STRU * pstrExpandedString ) /*++ - Routine Description: - Expand the environment variables in a string - Arguments: - pszString - String with environment variables to expand pstrExpandedString - Receives expanded string on success - Return Value: - HRESULT - --*/ { HRESULT hr = S_OK; DWORD cchNewSize = 0; - if ( pszString == NULL || pstrExpandedString == NULL ) { @@ -1225,7 +1219,6 @@ Return Value: hr = HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER ); goto Exit; } - cchNewSize = ExpandEnvironmentStrings( pszString, pstrExpandedString->QueryStr(), pstrExpandedString->QuerySizeCCH() ); @@ -1234,7 +1227,6 @@ Return Value: hr = HRESULT_FROM_WIN32( GetLastError() ); goto Exit; } - if ( cchNewSize > pstrExpandedString->QuerySizeCCH() ) { hr = pstrExpandedString->Resize( @@ -1244,13 +1236,11 @@ Return Value: { goto Exit; } - cchNewSize = ExpandEnvironmentStrings( pszString, pstrExpandedString->QueryStr(), pstrExpandedString->QuerySizeCCH() ); - if ( cchNewSize == 0 || cchNewSize > pstrExpandedString->QuerySizeCCH() ) { @@ -1258,14 +1248,10 @@ Return Value: goto Exit; } } - pstrExpandedString->SyncWithBuffer(); - hr = S_OK; - Exit: - return hr; } -#pragma warning(default:4267) +#pragma warning( pop ) diff --git a/src/AspNetCoreModuleV2/IISLib/stringu.h b/src/AspNetCoreModuleV2/IISLib/stringu.h index 6f27c5421d..f60f04cfbb 100644 --- a/src/AspNetCoreModuleV2/IISLib/stringu.h +++ b/src/AspNetCoreModuleV2/IISLib/stringu.h @@ -4,8 +4,12 @@ #pragma once #include "buffer.h" +#include #include +#pragma warning( push ) +#pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS ) + class STRU { @@ -349,13 +353,12 @@ public: __in PCWSTR pwszFormatString, va_list argsList ); - + static HRESULT ExpandEnvironmentVariables( __in PCWSTR pszString, __out STRU * pstrExpandedString ); - private: // @@ -425,3 +428,4 @@ MakePathCanonicalizationProof( IN PCWSTR pszName, OUT STRU * pstrPath ); +#pragma warning( pop ) diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp b/src/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp index d8d28e5a28..c1444a8571 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp @@ -184,7 +184,7 @@ http_get_application_properties( return E_FAIL; } - auto pConfiguration = pInProcessApplication->QueryConfig(); + const auto& pConfiguration = pInProcessApplication->QueryConfig(); pIISCofigurationData->pInProcessApplication = pInProcessApplication; pIISCofigurationData->pwzFullApplicationPath = SysAllocString(pInProcessApplication->QueryApplicationPhysicalPath().c_str()); diff --git a/src/AspNetCoreModuleV2/RequestHandlerLib/AppOfflineTrackingApplication.cpp b/src/AspNetCoreModuleV2/RequestHandlerLib/AppOfflineTrackingApplication.cpp index 0b987bf8cd..a946e7c2dc 100644 --- a/src/AspNetCoreModuleV2/RequestHandlerLib/AppOfflineTrackingApplication.cpp +++ b/src/AspNetCoreModuleV2/RequestHandlerLib/AppOfflineTrackingApplication.cpp @@ -38,7 +38,7 @@ HRESULT AppOfflineTrackingApplication::StartMonitoringAppOflineImpl() { if (m_fileWatcher) { - RETURN_IF_FAILED(E_UNEXPECTED); + RETURN_HR(E_UNEXPECTED); } m_fileWatcher = std::make_unique();