From 27476401c5e5295e1b1e90a3bf3b0b502f4793ce Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Thu, 3 Oct 2024 19:09:20 -0700 Subject: [PATCH 1/8] Enable code analysis and fix NULL usage. --- .../AspNetCore/applicationinfo.cpp | 2 +- .../CommonLib/CommonLib.vcxproj | 3 +- .../AspNetCoreModuleV2/CommonLib/sttimer.h | 18 +- .../CommonLibTests/CommonLibTests.vcxproj | 2 +- .../AspNetCoreModuleV2/DefaultRules.ruleset | 130 ++++--- .../IIS/AspNetCoreModuleV2/IISLib/ahutil.cpp | 126 +++---- .../IIS/AspNetCoreModuleV2/IISLib/base64.cpp | 20 +- .../IIS/AspNetCoreModuleV2/IISLib/hashtable.h | 84 ++--- .../IIS/AspNetCoreModuleV2/IISLib/listentry.h | 2 +- .../IIS/AspNetCoreModuleV2/IISLib/multisz.cpp | 32 +- .../AspNetCoreModuleV2/IISLib/multisza.cpp | 32 +- .../IIS/AspNetCoreModuleV2/IISLib/multisza.h | 16 +- .../IIS/AspNetCoreModuleV2/IISLib/reftrace.h | 2 +- .../IIS/AspNetCoreModuleV2/IISLib/rwlock.h | 8 +- .../IIS/AspNetCoreModuleV2/IISLib/stringa.cpp | 67 ++-- .../IIS/AspNetCoreModuleV2/IISLib/tracelog.c | 14 +- .../InProcessRequestHandler/dllmain.cpp | 8 +- .../inprocessapplication.cpp | 6 +- .../inprocesshandler.cpp | 20 +- .../managedexports.cpp | 16 +- .../OutOfProcessRequestHandler/dllmain.cpp | 22 +- .../forwarderconnection.cpp | 2 +- .../forwarderconnection.h | 4 +- .../forwardinghandler.cpp | 252 ++++++------- .../forwardinghandler.h | 2 + .../outprocessapplication.cpp | 12 +- .../processmanager.cpp | 16 +- .../processmanager.h | 24 +- .../responseheaderhash.h | 6 +- .../serverprocess.cpp | 342 +++++++++--------- .../url_utility.cpp | 16 +- .../websockethandler.cpp | 59 +-- .../winhttphelper.cpp | 12 +- .../RequestHandlerLib/filewatcher.cpp | 6 +- .../requesthandler_config.cpp | 60 +-- .../RequestHandlerLib/requesthandler_config.h | 2 +- .../AspNetCoreModuleV2/gtest/gtest.vcxproj | 1 + src/Servers/IIS/Directory.Build.props | 2 +- src/Servers/IIS/build/Build.Common.Settings | 6 + 39 files changed, 748 insertions(+), 706 deletions(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp b/src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp index 519a36da628e..93ef956c00b2 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp @@ -301,7 +301,7 @@ APPLICATION_INFO::HandleShadowCopy(const ShimOptions& options, IHttpContext& pHt auto shadowCopyBaseDirectory = std::filesystem::directory_entry(shadowCopyPath); if (!shadowCopyBaseDirectory.exists()) { - CreateDirectory(shadowCopyBaseDirectory.path().wstring().c_str(), NULL); + CreateDirectory(shadowCopyBaseDirectory.path().wstring().c_str(), nullptr); } for (auto& entry : std::filesystem::directory_iterator(shadowCopyPath)) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj index 4e8a906e079f..1525039d18a9 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj @@ -1,10 +1,11 @@ + {55494E58-E061-4C4C-A0A8-837008E72F85} NewCommon + false - ..\iislib;$(LibNetHostPath) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/sttimer.h b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/sttimer.h index 86b62b6fcf2a..97efaf1fe631 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/sttimer.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/sttimer.h @@ -13,7 +13,7 @@ class STTIMER public: STTIMER() - : _pTimer( NULL ) + : _pTimer( nullptr ) { fInCanel = FALSE; } @@ -25,7 +25,7 @@ class STTIMER { CancelTimer(); CloseThreadpoolTimer( _pTimer ); - _pTimer = NULL; + _pTimer = nullptr; } } @@ -39,7 +39,7 @@ class STTIMER { _pTimer = CreateThreadpoolTimer( pfnCallback, pContext, - NULL ); + nullptr ); if ( !_pTimer ) { @@ -74,9 +74,9 @@ class STTIMER // re-enabled by setting non-zero initial wait or // period values. // - if (_pTimer != NULL) + if (_pTimer != nullptr) { - SetThreadpoolTimer(_pTimer, NULL, 0, 0); + SetThreadpoolTimer(_pTimer, nullptr, 0, 0); } return; @@ -106,7 +106,7 @@ class STTIMER // Wait until any callbacks queued prior to disabling // have completed. // - if (_pTimer != NULL) + if (_pTimer != nullptr) { WaitForThreadpoolTimerCallbacks(_pTimer, TRUE); } @@ -124,13 +124,13 @@ class STTIMER ) { STRU* pstruLogFilePath = (STRU*)Context; - HANDLE hStdoutHandle = NULL; + HANDLE hStdoutHandle = nullptr; SECURITY_ATTRIBUTES saAttr = { 0 }; HRESULT hr = S_OK; saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; - saAttr.lpSecurityDescriptor = NULL; + saAttr.lpSecurityDescriptor = nullptr; hStdoutHandle = CreateFileW(pstruLogFilePath->QueryStr(), FILE_READ_DATA, @@ -138,7 +138,7 @@ class STTIMER &saAttr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, - NULL); + nullptr); if (hStdoutHandle == INVALID_HANDLE_VALUE) { hr = HRESULT_FROM_WIN32(GetLastError()); diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLibTests/CommonLibTests.vcxproj b/src/Servers/IIS/AspNetCoreModuleV2/CommonLibTests/CommonLibTests.vcxproj index e85b795c685a..e2e17265c7c8 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLibTests/CommonLibTests.vcxproj +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLibTests/CommonLibTests.vcxproj @@ -9,7 +9,7 @@ {1eac8125-1765-4e2d-8cbe-56dc98a1c8c1} Win32Proj Application - $(PlatformToolsetVersion) + v$(PlatformToolsetVersion) Unicode true true diff --git a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset index 1c2bbdaeaf40..147ad0a5677e 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset +++ b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset @@ -1,5 +1,5 @@  - + @@ -12,14 +12,14 @@ - + - + - - + + @@ -27,73 +27,82 @@ - + - - + + - + - - + + - - - + + + - + - + - + - - - + + + - + + + - - - + + + - - - - + + + + + - + - - + + + - - - - - + + + + + - - - - - - + + + + + + - + + + + + + @@ -142,7 +151,7 @@ - + @@ -213,9 +222,9 @@ - - - + + + @@ -239,7 +248,7 @@ - + @@ -282,19 +291,19 @@ - - + + - + - + - + @@ -319,7 +328,7 @@ - + @@ -338,7 +347,7 @@ - + @@ -383,14 +392,14 @@ - + - - - - + + + + @@ -418,6 +427,7 @@ + diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/ahutil.cpp b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/ahutil.cpp index 449469ea1b0b..8aa85ede2e88 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/ahutil.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/ahutil.cpp @@ -43,7 +43,7 @@ SetElementProperty( if( bstrPropName ) { SysFreeString( bstrPropName ); - bstrPropName = NULL; + bstrPropName = nullptr; } return hr; @@ -90,9 +90,9 @@ GetElementStringProperty( { HRESULT hr = S_OK; BSTR bstrPropName = SysAllocString( szPropName ); - IAppHostProperty* pProperty = NULL; + IAppHostProperty* pProperty = nullptr; - *pbstrPropValue = NULL; + *pbstrPropValue = nullptr; if (!bstrPropName) { @@ -140,8 +140,8 @@ GetElementStringProperty( { HRESULT hr = S_OK; BSTR bstrPropName = SysAllocString( szPropName ); - IAppHostProperty* pProperty = NULL; - BSTR bstrPropValue = NULL; + IAppHostProperty* pProperty = nullptr; + BSTR bstrPropValue = nullptr; if (!bstrPropName) { @@ -199,7 +199,7 @@ GetElementChildByName( ) { BSTR bstrElementName = SysAllocString(pszElementName); - if (bstrElementName == NULL) + if (bstrElementName == nullptr) { return E_OUTOFMEMORY; } @@ -235,13 +235,13 @@ GetElementBoolProperty( ) { HRESULT hr = S_OK; - IAppHostProperty * pProperty = NULL; + IAppHostProperty * pProperty = nullptr; VARIANT varValue; VariantInit( &varValue ); BSTR bstrPropertyName = SysAllocString(pszPropertyName); - if ( bstrPropertyName == NULL ) + if ( bstrPropertyName == nullptr ) { hr = E_OUTOFMEMORY; DBGERROR_HR(hr); @@ -275,16 +275,16 @@ GetElementBoolProperty( VariantClear( &varValue ); - if ( bstrPropertyName != NULL ) + if ( bstrPropertyName != nullptr ) { SysFreeString( bstrPropertyName ); - bstrPropertyName = NULL; + bstrPropertyName = nullptr; } - if ( pProperty != NULL ) + if ( pProperty != nullptr ) { pProperty->Release(); - pProperty = NULL; + pProperty = nullptr; } return hr; @@ -299,13 +299,13 @@ GetElementDWORDProperty( ) { HRESULT hr = S_OK; - IAppHostProperty * pProperty = NULL; + IAppHostProperty * pProperty = nullptr; VARIANT varValue; VariantInit( &varValue ); BSTR bstrName = SysAllocString(pwszName); - if ( bstrName == NULL ) + if ( bstrName == nullptr ) { hr = E_OUTOFMEMORY; DBGERROR_HR(hr); @@ -338,16 +338,16 @@ GetElementDWORDProperty( VariantClear( &varValue ); - if ( pProperty != NULL ) + if ( pProperty != nullptr ) { pProperty->Release(); - pProperty = NULL; + pProperty = nullptr; } - if ( bstrName != NULL ) + if ( bstrName != nullptr ) { SysFreeString( bstrName ); - bstrName = NULL; + bstrName = nullptr; } return hr; @@ -361,13 +361,13 @@ GetElementLONGLONGProperty( ) { HRESULT hr = S_OK; - IAppHostProperty * pProperty = NULL; + IAppHostProperty * pProperty = nullptr; VARIANT varValue; VariantInit( &varValue ); BSTR bstrName = SysAllocString(pwszName); - if ( bstrName == NULL ) + if ( bstrName == nullptr ) { hr = E_OUTOFMEMORY; DBGERROR_HR(hr); @@ -400,16 +400,16 @@ GetElementLONGLONGProperty( VariantClear( &varValue ); - if ( pProperty != NULL ) + if ( pProperty != nullptr ) { pProperty->Release(); - pProperty = NULL; + pProperty = nullptr; } - if ( bstrName != NULL ) + if ( bstrName != nullptr ) { SysFreeString( bstrName ); - bstrName = NULL; + bstrName = nullptr; } return hr; @@ -423,13 +423,13 @@ GetElementRawTimeSpanProperty( ) { HRESULT hr = S_OK; - IAppHostProperty * pProperty = NULL; + IAppHostProperty * pProperty = nullptr; VARIANT varValue; VariantInit( &varValue ); BSTR bstrPropertyName = SysAllocString(pszPropertyName); - if ( bstrPropertyName == NULL ) + if ( bstrPropertyName == nullptr ) { hr = HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY ); goto Finished; @@ -463,16 +463,16 @@ GetElementRawTimeSpanProperty( VariantClear( &varValue ); - if ( bstrPropertyName != NULL ) + if ( bstrPropertyName != nullptr ) { SysFreeString( bstrPropertyName ); - bstrPropertyName = NULL; + bstrPropertyName = nullptr; } - if ( pProperty != NULL ) + if ( pProperty != nullptr ) { pProperty->Release(); - pProperty = NULL; + pProperty = nullptr; } return hr; @@ -630,7 +630,7 @@ FindElementInCollection( DWORD count; DWORD i; - BSTR bstrKeyName = NULL; + BSTR bstrKeyName = nullptr; PFN_FIND_COMPARE_PROC compareProc; compareProc = (BehaviorFlags & FIND_ELEMENT_CASE_INSENSITIVE) @@ -738,7 +738,7 @@ VariantAssign( pv->vt = VT_BSTR; pv->bstrVal = bstr; - bstr = NULL; + bstr = nullptr; exit: @@ -761,9 +761,9 @@ GetLocationFromFile( CComPtr pLocationCollection; CComPtr pLocation; - BSTR bstrLocationPath = NULL; + BSTR bstrLocationPath = nullptr; - *ppLocation = NULL; + *ppLocation = nullptr; *pFound = FALSE; hr = GetLocationCollection( pAdminMgr, @@ -819,7 +819,7 @@ GetLocationFromFile( pLocation.Release(); SysFreeString( bstrLocationPath ); - bstrLocationPath = NULL; + bstrLocationPath = nullptr; } exit: @@ -847,10 +847,10 @@ GetSectionFromLocation( VARIANT varIndex; VariantInit( &varIndex ); - BSTR bstrSectionName = NULL; + BSTR bstrSectionName = nullptr; *pFound = FALSE; - *ppSectionElement = NULL; + *ppSectionElement = nullptr; hr = pLocation->get_Count( &count ); if( FAILED(hr) ) @@ -890,7 +890,7 @@ GetSectionFromLocation( pSectionElement.Release(); SysFreeString( bstrSectionName ); - bstrSectionName = NULL; + bstrSectionName = nullptr; } exit: @@ -914,7 +914,7 @@ GetAdminElement( BSTR bstrConfigPath = SysAllocString(szConfigPath); BSTR bstrElementName = SysAllocString(szElementName); - if (bstrConfigPath == NULL || bstrElementName == NULL) + if (bstrConfigPath == nullptr || bstrElementName == nullptr) { hr = E_OUTOFMEMORY; DBGERROR_HR(hr); @@ -933,15 +933,15 @@ GetAdminElement( exit: - if ( bstrElementName != NULL ) + if ( bstrElementName != nullptr ) { SysFreeString(bstrElementName); - bstrElementName = NULL; + bstrElementName = nullptr; } - if ( bstrConfigPath != NULL ) + if ( bstrConfigPath != nullptr ) { SysFreeString(bstrConfigPath); - bstrConfigPath = NULL; + bstrConfigPath = nullptr; } return hr; @@ -1168,7 +1168,7 @@ CompareElementName( OUT BOOL * pMatched ) { - BSTR bstrElementName = NULL; + BSTR bstrElementName = nullptr; *pMatched = FALSE; // until proven otherwise @@ -1258,9 +1258,9 @@ GetSitesCollection( BSTR bstrConfigPath = SysAllocString(szConfigPath); BSTR bstrSitesSectionName = SysAllocString(L"system.applicationHost/sites"); - *pSitesCollection = NULL; + *pSitesCollection = nullptr; - if (bstrConfigPath == NULL || bstrSitesSectionName == NULL) + if (bstrConfigPath == nullptr || bstrSitesSectionName == nullptr) { hr = E_OUTOFMEMORY; DBGERROR_HR(hr); @@ -1309,9 +1309,9 @@ GetLocationCollection( CComPtr pConfigFile; BSTR bstrConfigPath = SysAllocString(szConfigPath); - *pLocationCollection = NULL; + *pLocationCollection = nullptr; - if (bstrConfigPath == NULL) + if (bstrConfigPath == nullptr) { hr = E_OUTOFMEMORY; DBGERROR_HR(hr); @@ -1378,7 +1378,7 @@ FindNextElement( OUT IAppHostElement ** pElement ) { - *pElement = NULL; + *pElement = nullptr; if (pIndex->Index.ulVal >= pIndex->Count) { @@ -1424,7 +1424,7 @@ FindNextChildElement( OUT IAppHostElement ** pElement ) { - *pElement = NULL; + *pElement = nullptr; if (pIndex->Index.ulVal >= pIndex->Count) { @@ -1470,7 +1470,7 @@ FindNextLocation( OUT IAppHostConfigLocation ** pLocation ) { - *pLocation = NULL; + *pLocation = nullptr; if (pIndex->Index.ulVal >= pIndex->Count) { @@ -1516,7 +1516,7 @@ FindNextLocationElement( OUT IAppHostElement ** pElement ) { - *pElement = NULL; + *pElement = nullptr; if (pIndex->Index.ulVal >= pIndex->Count) { @@ -1552,16 +1552,16 @@ Return Value: --*/ { HRESULT hr = S_OK; - IAppHostAdminManager *pAdminManager = NULL; + IAppHostAdminManager *pAdminManager = nullptr; - BSTR bstrConfigPath = NULL; + BSTR bstrConfigPath = nullptr; - IAppHostElement * pConfigRedirSection = NULL; + IAppHostElement * pConfigRedirSection = nullptr; BSTR bstrSectionName = SysAllocString(L"configurationRedirection"); - if ( bstrSectionName == NULL ) + if ( bstrSectionName == nullptr ) { hr = E_OUTOFMEMORY; DBGERROR_HR(hr); @@ -1569,7 +1569,7 @@ Return Value: } bstrConfigPath = SysAllocString( L"MACHINE/REDIRECTION" ); - if ( bstrConfigPath == NULL ) + if ( bstrConfigPath == nullptr ) { hr = E_OUTOFMEMORY; DBGERROR_HR(hr); @@ -1577,7 +1577,7 @@ Return Value: } hr = CoCreateInstance( CLSID_AppHostAdminManager, - NULL, + nullptr, CLSCTX_INPROC_SERVER, IID_IAppHostAdminManager, (VOID **)&pAdminManager ); @@ -1607,7 +1607,7 @@ Return Value: } pConfigRedirSection->Release(); - pConfigRedirSection = NULL; + pConfigRedirSection = nullptr; exit: @@ -1616,22 +1616,22 @@ Return Value: // dump config exception to setup log file (if available) // - if ( pConfigRedirSection != NULL ) + if ( pConfigRedirSection != nullptr ) { pConfigRedirSection->Release(); } - if ( pAdminManager != NULL ) + if ( pAdminManager != nullptr ) { pAdminManager->Release(); } - if ( bstrConfigPath != NULL ) + if ( bstrConfigPath != nullptr ) { SysFreeString( bstrConfigPath ); } - if ( bstrSectionName != NULL ) + if ( bstrSectionName != nullptr ) { SysFreeString( bstrSectionName ); } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.cpp b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.cpp index 0122dcb33ec5..b5c910b9b573 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.cpp @@ -49,11 +49,11 @@ Return Values: // Calculate encoded string size. cchEncoded = 1 + (cbDecodedBufferSize + 2) / 3 * 4; - if (NULL != pcchEncoded) { + if (nullptr != pcchEncoded) { *pcchEncoded = cchEncoded; } - if (cchEncodedStringSize == 0 && pszEncodedString == NULL) { + if (cchEncodedStringSize == 0 && pszEncodedString == nullptr) { return ERROR_SUCCESS; } @@ -177,7 +177,7 @@ constexpr auto NA = (255); BYTE * pbDecodeBuffer = (BYTE *) pDecodeBuffer; cchEncodedSize = (DWORD)wcslen(pszEncodedString); - if (NULL != pcbDecoded) { + if (nullptr != pcbDecoded) { *pcbDecoded = 0; } @@ -199,11 +199,11 @@ constexpr auto NA = (255); } } - if (NULL != pcbDecoded) { + if (nullptr != pcbDecoded) { *pcbDecoded = cbDecoded; } - if (cbDecodeBufferSize == 0 && pDecodeBuffer == NULL) { + if (cbDecodeBufferSize == 0 && pDecodeBuffer == nullptr) { return ERROR_SUCCESS; } @@ -288,11 +288,11 @@ Return Values: // Calculate encoded string size. cchEncoded = 1 + (cbDecodedBufferSize + 2) / 3 * 4; - if (NULL != pcchEncoded) { + if (nullptr != pcchEncoded) { *pcchEncoded = cchEncoded; } - if (cchEncodedStringSize == 0 && pszEncodedString == NULL) { + if (cchEncodedStringSize == 0 && pszEncodedString == nullptr) { return ERROR_SUCCESS; } @@ -416,7 +416,7 @@ Return Values: BYTE * pbDecodeBuffer = (BYTE *) pDecodeBuffer; cchEncodedSize = (DWORD)strlen(pszEncodedString); - if (NULL != pcbDecoded) { + if (nullptr != pcbDecoded) { *pcbDecoded = 0; } @@ -438,11 +438,11 @@ Return Values: } } - if (NULL != pcbDecoded) { + if (nullptr != pcbDecoded) { *pcbDecoded = cbDecoded; } - if (cbDecodeBufferSize == 0 && pDecodeBuffer == NULL) { + if (cbDecodeBufferSize == 0 && pDecodeBuffer == nullptr) { return ERROR_SUCCESS; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashtable.h b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashtable.h index cde38374fe67..6f0bb9de3610 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashtable.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashtable.h @@ -16,14 +16,14 @@ class HASH_NODE HASH_NODE( _Record * pRecord, DWORD dwHash - ) : _pNext (NULL), + ) : _pNext (nullptr), _pRecord (pRecord), _dwHash (dwHash) {} ~HASH_NODE() { - _ASSERTE(_pRecord == NULL); + _ASSERTE(_pRecord == nullptr); } private: @@ -57,7 +57,7 @@ class HASH_TABLE HASH_TABLE( VOID ) - : _ppBuckets( NULL ), + : _ppBuckets(nullptr), _nBuckets( 0 ), _nItems( 0 ) { @@ -158,7 +158,7 @@ class HASH_TABLE __deref_out HASH_NODE<_Record> ** ppNode, __deref_opt_out - HASH_NODE<_Record> *** pppPreviousNodeNextPointer = NULL + HASH_NODE<_Record> *** pppPreviousNodeNextPointer = nullptr ); VOID @@ -166,10 +166,10 @@ class HASH_TABLE HASH_NODE<_Record> * pNode ) { - if (pNode->_pRecord != NULL) + if (pNode->_pRecord != nullptr) { DereferenceRecord(pNode->_pRecord); - pNode->_pRecord = NULL; + pNode->_pRecord = nullptr; } delete pNode; @@ -210,8 +210,8 @@ HASH_TABLE<_Record,_Key>::Initialize( goto Failed; } - _ASSERTE(_ppBuckets == NULL ); - if ( _ppBuckets != NULL ) + _ASSERTE(_ppBuckets == nullptr); + if (_ppBuckets != nullptr) { hr = E_INVALIDARG; goto Failed; @@ -227,7 +227,7 @@ HASH_TABLE<_Record,_Key>::Initialize( GetProcessHeap(), HEAP_ZERO_MEMORY, nBuckets*sizeof(HASH_NODE<_Record> *)); - if (_ppBuckets == NULL) + if (_ppBuckets == nullptr) { hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); goto Failed; @@ -243,7 +243,7 @@ HASH_TABLE<_Record,_Key>::Initialize( HeapFree(GetProcessHeap(), 0, _ppBuckets); - _ppBuckets = NULL; + _ppBuckets = nullptr; } return hr; @@ -253,7 +253,7 @@ HASH_TABLE<_Record,_Key>::Initialize( template HASH_TABLE<_Record,_Key>::~HASH_TABLE() { - if (_ppBuckets == NULL) + if (_ppBuckets == nullptr) { return; } @@ -263,7 +263,7 @@ HASH_TABLE<_Record,_Key>::~HASH_TABLE() HeapFree(GetProcessHeap(), 0, _ppBuckets); - _ppBuckets = NULL; + _ppBuckets = nullptr; _nBuckets = 0; } @@ -288,8 +288,8 @@ template VOID HASH_TABLE<_Record,_Key>::Clear() { - HASH_NODE<_Record> *pCurrent; - HASH_NODE<_Record> *pNext; + HASH_NODE<_Record> *pCurrent = nullptr; + HASH_NODE<_Record> *pNext = nullptr; // This is here in the off cases where someone instantiates a hashtable // and then does an automatic "clear" before its destruction WITHOUT @@ -304,8 +304,8 @@ HASH_TABLE<_Record,_Key>::Clear() for (DWORD i=0; i<_nBuckets; i++) { pCurrent = _ppBuckets[i]; - _ppBuckets[i] = NULL; - while (pCurrent != NULL) + _ppBuckets[i] = nullptr; + while (pCurrent != nullptr) { pNext = pCurrent->_pNext; DeleteNode(pCurrent); @@ -318,7 +318,7 @@ HASH_TABLE<_Record,_Key>::Clear() } template -__success(*ppNode != NULL && return != FALSE) +__success(*ppNode != nullptr && return != FALSE) BOOL HASH_TABLE<_Record,_Key>::FindNodeInternal( _Key key, @@ -338,13 +338,13 @@ HASH_TABLE<_Record,_Key>::FindNodeInternal( This routine may be called under either read or write lock --*/ { - HASH_NODE<_Record> **ppPreviousNodeNextPointer; - HASH_NODE<_Record> *pNode; + HASH_NODE<_Record> **ppPreviousNodeNextPointer = nullptr; + HASH_NODE<_Record> *pNode = nullptr; BOOL fFound = FALSE; ppPreviousNodeNextPointer = _ppBuckets + (dwHash % _nBuckets); pNode = *ppPreviousNodeNextPointer; - while (pNode != NULL) + while (pNode != nullptr) { if (pNode->_dwHash == dwHash) { @@ -364,10 +364,10 @@ HASH_TABLE<_Record,_Key>::FindNodeInternal( pNode = *ppPreviousNodeNextPointer; } - __analysis_assume( (pNode == NULL && fFound == FALSE) || - (pNode != NULL && fFound == TRUE ) ); + __analysis_assume( (pNode == nullptr && fFound == FALSE) || + (pNode != nullptr && fFound == TRUE ) ); *ppNode = pNode; - if (pppPreviousNodeNextPointer != NULL) + if (pppPreviousNodeNextPointer != nullptr) { *pppPreviousNodeNextPointer = ppPreviousNodeNextPointer; } @@ -381,16 +381,16 @@ HASH_TABLE<_Record,_Key>::FindKey( _Record ** ppRecord ) { - HASH_NODE<_Record> *pNode; + HASH_NODE<_Record> *pNode = nullptr; - *ppRecord = NULL; + *ppRecord = nullptr; DWORD dwHash = CalcKeyHash(key); _tableLock.SharedAcquire(); if (FindNodeInternal(key, dwHash, &pNode) && - pNode->_pRecord != NULL) + pNode->_pRecord != nullptr) { ReferenceRecord(pNode->_pRecord); *ppRecord = pNode->_pRecord; @@ -421,9 +421,9 @@ HASH_TABLE<_Record,_Key>::InsertRecord( _Key key = ExtractKey(pRecord); DWORD dwHash = CalcKeyHash(key); HRESULT hr = S_OK; - HASH_NODE<_Record> * pNewNode; - HASH_NODE<_Record> * pNextNode; - HASH_NODE<_Record> ** ppPreviousNodeNextPointer; + HASH_NODE<_Record> * pNewNode = nullptr; + HASH_NODE<_Record> * pNextNode = nullptr; + HASH_NODE<_Record> ** ppPreviousNodeNextPointer = nullptr; // // Ownership of pRecord is not transferred to pNewNode yet, so remember @@ -432,7 +432,7 @@ HASH_TABLE<_Record,_Key>::InsertRecord( // which users may view as getting flushed out of the hash-table // pNewNode = new HASH_NODE<_Record>(pRecord, dwHash); - if (pNewNode == NULL) + if (pNewNode == nullptr) { hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); goto Finished; @@ -451,7 +451,7 @@ HASH_TABLE<_Record,_Key>::InsertRecord( // // If node already there, return error // - pNewNode->_pRecord = NULL; + pNewNode->_pRecord = nullptr; DeleteNode(pNewNode); // @@ -470,10 +470,10 @@ HASH_TABLE<_Record,_Key>::InsertRecord( pNewNode, pNextNode) != pNextNode); // pass ownership of pRecord now - if (pRecord != NULL) + if (pRecord != nullptr) { ReferenceRecord(pRecord); - pRecord = NULL; + pRecord = nullptr; } InterlockedIncrement((LONG *)&_nItems); @@ -498,8 +498,8 @@ HASH_TABLE<_Record,_Key>::DeleteKey( _Key key ) { - HASH_NODE<_Record> *pNode; - HASH_NODE<_Record> **ppPreviousNodeNextPointer; + HASH_NODE<_Record> *pNode = nullptr; + HASH_NODE<_Record> **ppPreviousNodeNextPointer = nullptr; DWORD dwHash = CalcKeyHash(key); @@ -531,7 +531,7 @@ HASH_TABLE<_Record,_Key>::DeleteIf( { ppPreviousNodeNextPointer = _ppBuckets + i; pNode = *ppPreviousNodeNextPointer; - while (pNode != NULL) + while (pNode != nullptr) { // // Non empty nodes deleted based on DeleteIf, empty nodes deleted @@ -569,9 +569,9 @@ HASH_TABLE<_Record,_Key>::Apply( for (DWORD i=0; i<_nBuckets; i++) { pNode = _ppBuckets[i]; - while (pNode != NULL) + while (pNode != nullptr) { - if (pNode->_pRecord != NULL) + if (pNode->_pRecord != nullptr) { pfnApply(pNode->_pRecord, pvContext); } @@ -624,7 +624,7 @@ HASH_TABLE<_Record,_Key>::RehashTableIfNeeded( GetProcessHeap(), HEAP_ZERO_MEMORY, nBuckets*sizeof(HASH_NODE<_Record> *)); - if (ppBuckets == NULL) + if (ppBuckets == nullptr) { goto Finished; } @@ -636,13 +636,13 @@ HASH_TABLE<_Record,_Key>::RehashTableIfNeeded( for (DWORD i=0; i<_nBuckets; i++) { pNode = _ppBuckets[i]; - while (pNode != NULL) + while (pNode != nullptr) { pNextNode = pNode->_pNext; ppNextPointer = ppBuckets + (pNode->_dwHash % nBuckets); pNewNextNode = *ppNextPointer; - while (pNewNextNode != NULL && + while (pNewNextNode != nullptr && pNewNextNode->_dwHash <= pNode->_dwHash) { ppNextPointer = &pNewNextNode->_pNext; @@ -658,7 +658,7 @@ HASH_TABLE<_Record,_Key>::RehashTableIfNeeded( HeapFree(GetProcessHeap(), 0, _ppBuckets); _ppBuckets = ppBuckets; _nBuckets = nBuckets; - ppBuckets = NULL; + ppBuckets = nullptr; Finished: diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/listentry.h b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/listentry.h index 80b70e97a937..31f2b9b17c06 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/listentry.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/listentry.h @@ -140,7 +140,7 @@ PopEntryList( { PSINGLE_LIST_ENTRY FirstEntry; FirstEntry = ListHead->Next; - if (FirstEntry != NULL) { + if (FirstEntry != nullptr) { ListHead->Next = FirstEntry->Next; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/multisz.cpp b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/multisz.cpp index 1342e2ffd28e..393a220d01ab 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/multisz.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/multisz.cpp @@ -35,7 +35,7 @@ MULTISZ::CalcLength( const WCHAR * str, count++; } - if( pcStrings != NULL ) { + if( pcStrings != nullptr ) { *pcStrings = count; } @@ -51,8 +51,8 @@ MULTISZ::FindString( const WCHAR * str ) const // Sanity check. // - DBG_ASSERT( QueryStr() != NULL ); - DBG_ASSERT( str != NULL ); + DBG_ASSERT( QueryStr() != nullptr ); + DBG_ASSERT( str != nullptr ); DBG_ASSERT( *str != '\0' ); // @@ -85,8 +85,8 @@ MULTISZ::FindStringNoCase( const WCHAR * str ) const // Sanity check. // - DBG_ASSERT( QueryStr() != NULL ); - DBG_ASSERT( str != NULL ); + DBG_ASSERT( QueryStr() != nullptr ); + DBG_ASSERT( str != nullptr ); DBG_ASSERT( *str != '\0' ); // @@ -149,7 +149,7 @@ MULTISZ::AuxInit( const WCHAR * pInit ) BOOL MULTISZ::AuxAppend( const WCHAR * pStr, UINT cbStr, BOOL fAddSlop ) { - DBG_ASSERT( pStr != NULL ); + DBG_ASSERT( pStr != nullptr ); UINT cbThis = QueryCB(); @@ -247,7 +247,7 @@ MULTISZ::CopyToBuffer( WCHAR * lpszBuffer, LPDWORD lpcch) const { BOOL fReturn = TRUE; - if ( lpcch == NULL) { + if ( lpcch == nullptr ) { SetLastError( ERROR_INVALID_PARAMETER); return ( FALSE); } @@ -305,7 +305,7 @@ MULTISZ::CopyToBuffer( __out_ecount_opt(*lpcch) WCHAR * lpszBuffer, LPDWORD lpcc { BOOL fReturn = TRUE; - if ( lpcch == NULL) { + if ( lpcch == nullptr ) { SetLastError( ERROR_INVALID_PARAMETER); return ( FALSE); } @@ -335,7 +335,7 @@ MULTISZ::Equals( // Compares this to pmszRhs, returns TRUE if equal // { - DBG_ASSERT( NULL != pmszRhs ); + DBG_ASSERT( nullptr != pmszRhs ); PCWSTR pszLhs = First( ); PCWSTR pszRhs = pmszRhs->First( ); @@ -345,9 +345,9 @@ MULTISZ::Equals( return FALSE; } - while( NULL != pszLhs ) + while( nullptr != pszLhs ) { - DBG_ASSERT( NULL != pszRhs ); + DBG_ASSERT( nullptr != pszRhs ); if( 0 != wcscmp( pszLhs, pszRhs ) ) { @@ -390,8 +390,8 @@ Return Value: { HRESULT hr = S_OK; - if ( pszList == NULL || - pmszList == NULL ) + if ( pszList == nullptr || + pmszList == nullptr ) { DBG_ASSERT( FALSE ); hr = HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER ); @@ -417,9 +417,9 @@ Return Value: pszCurrent = pszNext + 1, pszNext = wcschr( pszCurrent, L',' ) ) { - PCWSTR pszEnd = NULL; + PCWSTR pszEnd = nullptr; - if ( pszNext != NULL ) + if ( pszNext != nullptr ) { pszEnd = pszNext; } @@ -450,7 +450,7 @@ Return Value: } } - if ( pszNext == NULL ) + if ( pszNext == nullptr ) { break; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/multisza.cpp b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/multisza.cpp index 0f36fc663cc9..ebd9dc8002f7 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/multisza.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/multisza.cpp @@ -33,7 +33,7 @@ MULTISZA::CalcLength( const CHAR * str, count++; } - if( pcStrings != NULL ) { + if( pcStrings != nullptr ) { *pcStrings = count; } @@ -49,8 +49,8 @@ MULTISZA::FindString( const CHAR * str ) const // Sanity check. // - DBG_ASSERT( QueryStr() != NULL ); - DBG_ASSERT( str != NULL ); + DBG_ASSERT( QueryStr() != nullptr); + DBG_ASSERT( str != nullptr ); DBG_ASSERT( *str != '\0' ); // @@ -83,8 +83,8 @@ MULTISZA::FindStringNoCase( const CHAR * str ) const // Sanity check. // - DBG_ASSERT( QueryStr() != NULL ); - DBG_ASSERT( str != NULL ); + DBG_ASSERT( QueryStr() != nullptr); + DBG_ASSERT( str != nullptr); DBG_ASSERT( *str != '\0' ); // @@ -96,9 +96,7 @@ MULTISZA::FindStringNoCase( const CHAR * str ) const while( *multisz != '\0' ) { if( !_stricmp( multisz, str ) ) { - return TRUE; - } multisz += strlen( multisz ) + 1; @@ -147,7 +145,7 @@ MULTISZA::AuxInit( const CHAR * pInit ) BOOL MULTISZA::AuxAppend( const CHAR * pStr, UINT cbStr, BOOL fAddSlop ) { - DBG_ASSERT( pStr != NULL ); + DBG_ASSERT( pStr != nullptr); UINT cbThis = QueryCB(); @@ -240,7 +238,7 @@ MULTISZA::CopyToBuffer( __out_ecount_opt(*lpcch) CHAR * lpszBuffer, LPDWORD lpcc { BOOL fReturn = TRUE; - if ( lpcch == NULL) { + if ( lpcch == nullptr) { SetLastError( ERROR_INVALID_PARAMETER); return ( FALSE); } @@ -270,7 +268,7 @@ MULTISZA::Equals( // Compares this to pmszRhs, returns TRUE if equal // { - DBG_ASSERT( NULL != pmszRhs ); + DBG_ASSERT(nullptr != pmszRhs ); PCSTR pszLhs = First( ); PCSTR pszRhs = pmszRhs->First( ); @@ -280,9 +278,9 @@ MULTISZA::Equals( return FALSE; } - while( NULL != pszLhs ) + while( nullptr != pszLhs ) { - DBG_ASSERT( NULL != pszRhs ); + DBG_ASSERT( nullptr != pszRhs ); if( 0 != strcmp( pszLhs, pszRhs ) ) { @@ -325,8 +323,8 @@ Return Value: { HRESULT hr = S_OK; - if ( pszList == NULL || - pmszList == NULL ) + if ( pszList == nullptr || + pmszList == nullptr) { DBG_ASSERT( FALSE ); hr = HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER ); @@ -352,9 +350,9 @@ Return Value: pszCurrent = pszNext + 1, pszNext = strchr( pszCurrent, L',' ) ) { - PCSTR pszEnd = NULL; + PCSTR pszEnd = nullptr; - if ( pszNext != NULL ) + if ( pszNext != nullptr ) { pszEnd = pszNext; } @@ -385,7 +383,7 @@ Return Value: } } - if ( pszNext == NULL ) + if ( pszNext == nullptr ) { break; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/multisza.h b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/multisza.h index 7ea28881f3fb..7748fbc64438 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/multisza.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/multisza.h @@ -69,7 +69,7 @@ class MULTISZA : public BUFFER BOOL IsEmpty( VOID) const { return ( *QueryStr() == L'\0'); } BOOL Append( const CHAR * pchInit ) { - return ((pchInit != NULL) ? (AuxAppend( pchInit, + return ((pchInit != nullptr) ? (AuxAppend( pchInit, (DWORD) (::strlen(pchInit)) * sizeof(CHAR) )) : TRUE); @@ -77,7 +77,7 @@ class MULTISZA : public BUFFER BOOL Append( const CHAR * pchInit, DWORD cchLen ) { - return ((pchInit != NULL) ? (AuxAppend( pchInit, + return ((pchInit != nullptr) ? (AuxAppend( pchInit, cchLen * sizeof(CHAR))) : TRUE); } @@ -88,7 +88,7 @@ class MULTISZA : public BUFFER // Resets the internal string to be NULL string. Buffer remains cached. VOID Reset() - { DBG_ASSERT( QueryPtr() != NULL); + { DBG_ASSERT( QueryPtr() != nullptr ); QueryStr()[0] = L'\0'; QueryStr()[1] = L'\0'; m_cchLen = 2; @@ -97,7 +97,7 @@ class MULTISZA : public BUFFER BOOL Copy( const CHAR * pchInit, IN DWORD cbLen ) { if ( QueryPtr() ) { Reset(); } - return ( (pchInit != NULL) ? + return ( (pchInit != nullptr) ? AuxAppend( pchInit, cbLen, FALSE ): TRUE); } @@ -140,7 +140,7 @@ class MULTISZA : public BUFFER BOOL Clone( OUT MULTISZA * pstrClone) const { - return ((pstrClone == NULL) ? + return ((pstrClone == nullptr) ? (SetLastError(ERROR_INVALID_PARAMETER), FALSE) : (pstrClone->Copy( *this)) ); @@ -160,7 +160,7 @@ class MULTISZA : public BUFFER // static DWORD CalcLength( const CHAR * str, - LPDWORD pcStrings = NULL ); + LPDWORD pcStrings = nullptr ); // // Determine if the MULTISZA contains a specific string. @@ -185,11 +185,11 @@ class MULTISZA : public BUFFER // const CHAR * First( VOID ) const - { return *QueryStr() == L'\0' ? NULL : QueryStr(); } + { return *QueryStr() == L'\0' ? nullptr : QueryStr(); } const CHAR * Next( const CHAR * Current ) const { Current += ::strlen( Current ) + 1; - return *Current == L'\0' ? NULL : Current; } + return *Current == L'\0' ? nullptr : Current; } BOOL Equals( diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/reftrace.h b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/reftrace.h index e90ca0444a71..68e8221eee01 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/reftrace.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/reftrace.h @@ -23,7 +23,7 @@ extern "C" { // No-op value for the Context1,2,3 parameters of WriteRefTraceLogEx //#define REF_TRACE_EMPTY_CONTEXT ((PVOID) -1) -#define REF_TRACE_EMPTY_CONTEXT NULL +#define REF_TRACE_EMPTY_CONTEXT nullptr // diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/rwlock.h b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/rwlock.h index dc7ccf834bef..1db1627f0679 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/rwlock.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/rwlock.h @@ -160,21 +160,25 @@ class CWSDRWLock return S_OK; } + _Acquires_shared_lock_(this->m_rwLock) void SharedAcquire() { AcquireSRWLockShared(&m_rwLock); } - + + _Releases_shared_lock_(this->m_rwLock) void SharedRelease() { ReleaseSRWLockShared(&m_rwLock); } + _Acquires_exclusive_lock_(this->m_rwLock) void ExclusiveAcquire() { AcquireSRWLockExclusive(&m_rwLock); } - + + _Releases_exclusive_lock_(this->m_rwLock) void ExclusiveRelease() { ReleaseSRWLockExclusive(&m_rwLock); diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp index 8e2cbfe9caf0..b8ee1b11962f 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp @@ -32,7 +32,7 @@ STRA::STRA( --*/ { - _ASSERTE( NULL != pbInit ); + _ASSERTE( nullptr != pbInit ); _ASSERTE( cchInit > 0 ); _ASSERTE( pbInit[0] == '\0' ); } @@ -51,7 +51,7 @@ STRA::Equals( __in BOOL fIgnoreCase /*= FALSE*/ ) const { - _ASSERTE( NULL != pszRhs ); + _ASSERTE( nullptr != pszRhs ); if( fIgnoreCase ) { @@ -67,7 +67,7 @@ STRA::Equals( __in BOOL fIgnoreCase /*= FALSE*/ ) const { - _ASSERTE( NULL != pstrRhs ); + _ASSERTE( nullptr != pstrRhs ); return Equals( pstrRhs->QueryStr(), fIgnoreCase ); } @@ -142,7 +142,7 @@ STRA::Reset( // Resets the internal string to be NULL string. Buffer remains cached. // { - _ASSERTE( QueryStr() != NULL ); + _ASSERTE( QueryStr() != nullptr ); *(QueryStr()) = '\0'; m_cchLen = 0; } @@ -220,7 +220,7 @@ STRA::Copy( __in const STRA * pstrRhs ) { - _ASSERTE( pstrRhs != NULL ); + _ASSERTE( pstrRhs != nullptr ); return Copy( pstrRhs->QueryStr(), pstrRhs->QueryCCH() ); } @@ -323,7 +323,7 @@ STRA::Append( __in const STRA * pstrRhs ) { - _ASSERTE( pstrRhs != NULL ); + _ASSERTE( pstrRhs != nullptr ); return Append( pstrRhs->QueryStr(), pstrRhs->QueryCCH() ); } @@ -382,8 +382,8 @@ STRA::CopyToBuffer( // Makes a copy of the stored string into the given buffer // { - _ASSERTE( NULL != pszBuffer ); - _ASSERTE( NULL != pcb ); + _ASSERTE( nullptr != pszBuffer ); + _ASSERTE( nullptr != pcb ); HRESULT hr = S_OK; DWORD cbNeeded = QueryCB() + sizeof( CHAR ); @@ -464,6 +464,7 @@ Return Value: HRESULT hr = SafeVsnprintf(pszFormatString, argsList); +#pragma warning(suppress: 26477) va_end( argsList ); return hr; } @@ -675,7 +676,7 @@ Return Value: --*/ { LPCSTR pch = QueryStr(); - __analysis_assume( pch != NULL ); + __analysis_assume( pch != nullptr ); int i = 0; BYTE ch; HRESULT hr = S_OK; @@ -859,8 +860,8 @@ Return Value: 1, static_cast(pDest), 6, - NULL, - NULL); + nullptr, + nullptr); pDest += dwLen; pScan += 6; @@ -1000,7 +1001,7 @@ STRA::AuxAppend( __in DWORD cbOffset ) { - _ASSERTE( NULL != pStr ); + _ASSERTE( nullptr != pStr ); _ASSERTE( cbOffset <= QueryCB() ); ULONGLONG cb64NewSize = static_cast(cbOffset) + cbLen + sizeof( CHAR ); @@ -1070,8 +1071,8 @@ STRA::AuxAppendW( cchAppendW, QueryStr() + cbOffset, cbAvailable, - NULL, - NULL + nullptr, + nullptr ); if( 0 != cbRet ) { @@ -1104,10 +1105,10 @@ STRA::AuxAppendW( dwFlags, pszAppendW, cchAppendW, - NULL, + nullptr, 0, - NULL, - NULL + nullptr, + nullptr ); if( 0 == cbRet ) { @@ -1133,8 +1134,8 @@ STRA::AuxAppendW( cchAppendW, QueryStr() + cbOffset, cbAvailable, - NULL, - NULL + nullptr, + nullptr ); if( 0 == cbRet ) { @@ -1169,7 +1170,7 @@ STRA::AuxAppendWTruncate( // Cheesey WCHAR --> CHAR conversion // { - _ASSERTE( NULL != pszAppendW ); + _ASSERTE( nullptr != pszAppendW ); _ASSERTE( 0 == cbOffset || cbOffset == QueryCB() ); if( !pszAppendW ) @@ -1213,8 +1214,8 @@ STRA::ConvertUnicodeToCodePage( __in UINT uCodePage ) { - _ASSERTE(NULL != pszSrcUnicodeString); - _ASSERTE(NULL != pbufDstAnsiString); + _ASSERTE(nullptr != pszSrcUnicodeString); + _ASSERTE(nullptr != pbufDstAnsiString); DWORD dwFlags; @@ -1233,17 +1234,17 @@ STRA::ConvertUnicodeToCodePage( dwStringLen, static_cast(pbufDstAnsiString->QueryPtr()), static_cast(pbufDstAnsiString->QuerySize()), - NULL, - NULL); + nullptr, + nullptr); if ((iStrLen == 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) { iStrLen = WideCharToMultiByte(uCodePage, dwFlags, pszSrcUnicodeString, dwStringLen, - NULL, + nullptr, 0, - NULL, - NULL); + nullptr, + nullptr); if (iStrLen != 0) { // add one just for the extra NULL BOOL bTemp = pbufDstAnsiString->Resize(iStrLen + 1); @@ -1259,8 +1260,8 @@ STRA::ConvertUnicodeToCodePage( dwStringLen, static_cast(pbufDstAnsiString->QueryPtr()), static_cast(pbufDstAnsiString->QuerySize()), - NULL, - NULL); + nullptr, + nullptr); } } @@ -1387,7 +1388,7 @@ STRA::StartsWith( __in const STRA * pStraPrefix, __in bool fIgnoreCase) const { - _ASSERTE( pStraPrefix != NULL ); + _ASSERTE( pStraPrefix != nullptr ); return StartsWith(pStraPrefix->QueryStr(), fIgnoreCase); } @@ -1436,7 +1437,7 @@ STRA::StartsWith( __in PCSTR pszPrefix, __in bool fIgnoreCase) const { - if (pszPrefix == NULL) + if (pszPrefix == nullptr) { return FALSE; } @@ -1488,7 +1489,7 @@ STRA::EndsWith( __in const STRA * pStraSuffix, __in bool fIgnoreCase) const { - _ASSERTE( pStraSuffix != NULL ); + _ASSERTE( pStraSuffix != nullptr ); return EndsWith(pStraSuffix->QueryStr(), fIgnoreCase); } @@ -1541,7 +1542,7 @@ STRA::EndsWith( { PSTR pszString = QueryStr(); - if (pszSuffix == NULL) + if (pszSuffix == nullptr) { return FALSE; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/tracelog.c b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/tracelog.c index 6c0d08029932..12c41665bdf8 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/tracelog.c +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/tracelog.c @@ -46,7 +46,7 @@ Return Value: ULONG ulEntrySize = 0; ULONG ulTmpResult = 0; ULONG ulExtraBytesInHeader = 0; - PTRACE_LOG log = NULL; + PTRACE_LOG log = nullptr; HRESULT hr = S_OK; // @@ -74,7 +74,7 @@ Return Value: if ( FAILED(hr) ) { SetLastError( ERROR_ARITHMETIC_OVERFLOW ); - return NULL; + return nullptr; } // @@ -85,7 +85,7 @@ Return Value: if ( FAILED(hr) ) { SetLastError( ERROR_ARITHMETIC_OVERFLOW ); - return NULL; + return nullptr; } // @@ -96,13 +96,13 @@ Return Value: if ( FAILED(hr) ) { SetLastError( ERROR_ARITHMETIC_OVERFLOW ); - return NULL; + return nullptr; } if ( ulTotalSize > (ULONG) 0x7FFFFFFF ) { SetLastError( ERROR_ARITHMETIC_OVERFLOW ); - return NULL; + return nullptr; } // @@ -115,7 +115,7 @@ Return Value: // Initialize it. // - if( log != NULL ) { + if( log != nullptr ) { RtlZeroMemory( log, ulTotalSize ); @@ -151,7 +151,7 @@ Return Value: --*/ { - if ( Log != NULL ) { + if ( Log != nullptr ) { //DBG_ASSERT( Log->Signature == TRACE_LOG_SIGNATURE ); Log->Signature = TRACE_LOG_SIGNATURE_X; diff --git a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp index 3040e06924a5..509dc3f3e848 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp @@ -24,10 +24,10 @@ DECLARE_DEBUG_PRINT_OBJECT("aspnetcorev2_inprocess.dll"); BOOL g_fGlobalInitialize = FALSE; BOOL g_fProcessDetach = FALSE; SRWLOCK g_srwLockRH; -IHttpServer * g_pHttpServer = NULL; +IHttpServer * g_pHttpServer = nullptr; HINSTANCE g_hWinHttpModule; HINSTANCE g_hAspNetCoreModule; -HANDLE g_hEventLog = NULL; +HANDLE g_hEventLog = nullptr; bool g_fInProcessApplicationCreated = false; std::string g_errorPageContent; HINSTANCE g_hServerModule; @@ -50,11 +50,11 @@ InitializeGlobalConfiguration( if (pServer->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); } DebugInitializeFromConfig(*pServer, *pHttpApplication); diff --git a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp index c510ecdb7f97..2fc8b54ba624 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp @@ -14,7 +14,7 @@ #include "Environment.h" #include "HostFxr.h" -IN_PROCESS_APPLICATION* IN_PROCESS_APPLICATION::s_Application = NULL; +IN_PROCESS_APPLICATION* IN_PROCESS_APPLICATION::s_Application = nullptr; IN_PROCESS_APPLICATION::IN_PROCESS_APPLICATION( IHttpServer& pHttpServer, @@ -327,11 +327,11 @@ IN_PROCESS_APPLICATION::ExecuteApplication() if (m_pConfig->QueryCallStartupHook()) { - PWSTR startupHookValue = NULL; + PWSTR startupHookValue = nullptr; // Will get property not found if the environment variable isn't set. context->m_hostFxr.GetRuntimePropertyValue(DOTNETCORE_STARTUP_HOOK, &startupHookValue); - if (startupHookValue == NULL) + if (startupHookValue == nullptr) { RETURN_IF_NOT_ZERO(context->m_hostFxr.SetRuntimePropertyValue(DOTNETCORE_STARTUP_HOOK, ASPNETCORE_STARTUP_ASSEMBLY)); } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp index 8f5e3ae56b75..d4a68da2bafa 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp @@ -6,7 +6,7 @@ #include "ShuttingDownApplication.h" #include "ntassert.h" -ALLOC_CACHE_HANDLER * IN_PROCESS_HANDLER::sm_pAlloc = NULL; +ALLOC_CACHE_HANDLER * IN_PROCESS_HANDLER::sm_pAlloc = nullptr; IN_PROCESS_HANDLER::IN_PROCESS_HANDLER( _In_ std::unique_ptr pApplication, @@ -37,7 +37,7 @@ IN_PROCESS_HANDLER::ExecuteRequestHandler() { ::RaiseEvent(m_pW3Context, nullptr); - if (m_pRequestHandler == NULL) + if (m_pRequestHandler == nullptr) { ::RaiseEvent(m_pW3Context, nullptr, RQ_NOTIFICATION_FINISH_REQUEST); return RQ_NOTIFICATION_FINISH_REQUEST; @@ -198,10 +198,10 @@ IN_PROCESS_HANDLER::SetManagedHttpContext( // static void * IN_PROCESS_HANDLER::operator new(size_t) { - DBG_ASSERT(sm_pAlloc != NULL); - if (sm_pAlloc == NULL) + DBG_ASSERT(sm_pAlloc != nullptr); + if (sm_pAlloc == nullptr) { - return NULL; + return nullptr; } return sm_pAlloc->Alloc(); } @@ -209,8 +209,8 @@ void * IN_PROCESS_HANDLER::operator new(size_t) // static void IN_PROCESS_HANDLER::operator delete(void * pMemory) { - DBG_ASSERT(sm_pAlloc != NULL); - if (sm_pAlloc != NULL) + DBG_ASSERT(sm_pAlloc != nullptr); + if (sm_pAlloc != nullptr) { sm_pAlloc->Free(pMemory); } @@ -234,7 +234,7 @@ HRESULT HRESULT hr = S_OK; sm_pAlloc = new ALLOC_CACHE_HANDLER; - if (sm_pAlloc == NULL) + if (sm_pAlloc == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -255,9 +255,9 @@ HRESULT void IN_PROCESS_HANDLER::StaticTerminate(VOID) { - if (sm_pAlloc != NULL) + if (sm_pAlloc != nullptr) { delete sm_pAlloc; - sm_pAlloc = NULL; + sm_pAlloc = nullptr; } } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp index 23639860527a..eea153ca6954 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp @@ -29,7 +29,7 @@ class __declspec(uuid("1a2acc57-cae2-4f28-b4ab-00c8f96b12ec")) PCSTR GetTrailer( _In_ PCSTR pszHeaderName, - _Out_ USHORT* pcchHeaderValue = NULL + _Out_ USHORT* pcchHeaderValue = nullptr ) const = 0; virtual @@ -70,7 +70,7 @@ register_callbacks( _In_ VOID* pvShutdownHandlerContext ) { - if (pInProcessApplication == NULL) + if (pInProcessApplication == nullptr) { return E_INVALIDARG; } @@ -117,6 +117,8 @@ http_get_server_variable( PCWSTR pszVariableValue; DWORD cbLength; + *pwszReturn = nullptr; + HRESULT hr = pInProcessHandler ->QueryHttpContext() ->GetServerVariable(pszVariableName, &pszVariableValue, &cbLength); @@ -128,7 +130,7 @@ http_get_server_variable( *pwszReturn = SysAllocString(pszVariableValue); - if (*pwszReturn == NULL) + if (*pwszReturn == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -245,7 +247,7 @@ http_get_application_properties( ) { auto pInProcessApplication = IN_PROCESS_APPLICATION::GetInstance(); - if (pInProcessApplication == NULL) + if (pInProcessApplication == nullptr) { return E_FAIL; } @@ -277,7 +279,7 @@ http_read_request_bytes( { HRESULT hr = S_OK; - if (pInProcessHandler == NULL) + if (pInProcessHandler == nullptr) { return E_FAIL; } @@ -522,7 +524,7 @@ EXTERN_C __declspec(dllexport) HRESULT http_stop_calls_into_managed(_In_ IN_PROCESS_APPLICATION* pInProcessApplication) { - if (pInProcessApplication == NULL) + if (pInProcessApplication == nullptr) { return E_INVALIDARG; } @@ -535,7 +537,7 @@ EXTERN_C __declspec(dllexport) HRESULT http_stop_incoming_requests(_In_ IN_PROCESS_APPLICATION* pInProcessApplication) { - if (pInProcessApplication == NULL) + if (pInProcessApplication == nullptr) { return E_INVALIDARG; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp index a89165dd72b4..449ec6a2877a 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp @@ -16,12 +16,12 @@ BOOL g_fProcessDetach = FALSE; DWORD g_OptionalWinHttpFlags = 0; DWORD g_dwTlsIndex = TLS_OUT_OF_INDEXES; SRWLOCK g_srwLockRH; -HINTERNET g_hWinhttpSession = NULL; -IHttpServer * g_pHttpServer = NULL; +HINTERNET g_hWinhttpSession = nullptr; +IHttpServer * g_pHttpServer = nullptr; HINSTANCE g_hWinHttpModule; HINSTANCE g_hOutOfProcessRHModule; HINSTANCE g_hAspNetCoreModule; -HANDLE g_hEventLog = NULL; +HANDLE g_hEventLog = nullptr; VOID InitializeGlobalConfiguration( @@ -45,11 +45,11 @@ InitializeGlobalConfiguration( g_pHttpServer = pServer; if (pServer->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); } if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, @@ -65,7 +65,7 @@ InitializeGlobalConfiguration( cbData = sizeof(dwData); if ((RegQueryValueEx(hKey, L"OptionalWinHttpFlags", - NULL, + nullptr, &dwType, (LPBYTE)&dwData, &cbData) == NO_ERROR) && @@ -77,7 +77,7 @@ InitializeGlobalConfiguration( cbData = sizeof(dwData); if ((RegQueryValueEx(hKey, L"EnableReferenceCountTracing", - NULL, + nullptr, &dwType, (LPBYTE)&dwData, &cbData) == NO_ERROR) && @@ -151,12 +151,16 @@ EnsureOutOfProcessInitializtion(IHttpApplication *pHttpApplication) } } +#pragma warning(push) +#pragma warning(disable: 26477) // NULL usage via Windows header g_hWinhttpSession = WinHttpOpen(L"", WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, WINHTTP_FLAG_ASYNC); - FINISHED_LAST_ERROR_IF(g_hWinhttpSession == NULL); +#pragma warning(pop) + + FINISHED_LAST_ERROR_IF(g_hWinhttpSession == nullptr); // // Don't set non-blocking callbacks WINHTTP_OPTION_ASSURED_NON_BLOCKING_CALLBACKS, @@ -171,7 +175,7 @@ EnsureOutOfProcessInitializtion(IHttpApplication *pHttpApplication) FORWARDING_HANDLER::OnWinHttpCompletion, (WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS | WINHTTP_CALLBACK_STATUS_SENDING_REQUEST), - NULL) == WINHTTP_INVALID_STATUS_CALLBACK); + 0) == WINHTTP_INVALID_STATUS_CALLBACK); // // Make sure we see the redirects (rather than winhttp doing it diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwarderconnection.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwarderconnection.cpp index ee49e992422c..bb335374b234 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwarderconnection.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwarderconnection.cpp @@ -7,7 +7,7 @@ FORWARDER_CONNECTION::FORWARDER_CONNECTION( VOID ) : m_cRefs (1), - m_hConnection (NULL) + m_hConnection (nullptr) { } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwarderconnection.h b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwarderconnection.h index 232e23988826..89ba58d560c5 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwarderconnection.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwarderconnection.h @@ -88,10 +88,10 @@ class FORWARDER_CONNECTION ~FORWARDER_CONNECTION() { - if (m_hConnection != NULL) + if (m_hConnection != nullptr) { WinHttpCloseHandle(m_hConnection); - m_hConnection = NULL; + m_hConnection = nullptr; } } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp index d30883ea5332..2ebc0c6ddbf8 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp @@ -20,10 +20,10 @@ C_ASSERT(sizeof(FORWARDING_HANDLER) <= 632); #define FORWARDING_HANDLER_SIGNATURE ((DWORD)'FHLR') #define FORWARDING_HANDLER_SIGNATURE_FREE ((DWORD)'fhlr') -ALLOC_CACHE_HANDLER * FORWARDING_HANDLER::sm_pAlloc = NULL; -TRACE_LOG * FORWARDING_HANDLER::sm_pTraceLog = NULL; +ALLOC_CACHE_HANDLER * FORWARDING_HANDLER::sm_pAlloc = nullptr; +TRACE_LOG * FORWARDING_HANDLER::sm_pTraceLog = nullptr; PROTOCOL_CONFIG FORWARDING_HANDLER::sm_ProtocolConfig; -RESPONSE_HEADER_HASH * FORWARDING_HANDLER::sm_pResponseHeaderHash = NULL; +RESPONSE_HEADER_HASH * FORWARDING_HANDLER::sm_pResponseHeaderHash = nullptr; FORWARDING_HANDLER::FORWARDING_HANDLER( _In_ IHttpContext *pW3Context, @@ -36,12 +36,12 @@ FORWARDING_HANDLER::FORWARDING_HANDLER( m_fDoReverseRewriteHeaders(FALSE), m_fFinishRequest(FALSE), m_fHasError(FALSE), - m_pszHeaders(NULL), + m_pszHeaders(nullptr), m_cchHeaders(0), m_BytesToReceive(0), m_BytesToSend(0), m_fWebSocketEnabled(FALSE), - m_pWebSocket(NULL), + m_pWebSocket(nullptr), m_dwHandlers (1), // default http handler m_fDoneAsyncCompletion(FALSE), m_fHttpHandleInClose(FALSE), @@ -87,7 +87,7 @@ FORWARDING_HANDLER::~FORWARDING_HANDLER( if (m_pWebSocket) { m_pWebSocket->Terminate(); - m_pWebSocket = NULL; + m_pWebSocket = nullptr; } } @@ -100,12 +100,12 @@ FORWARDING_HANDLER::ExecuteRequestHandler() BOOL fRequestLocked = FALSE; BOOL fFailedToStartKestrel = FALSE; BOOL fSecure = FALSE; - HINTERNET hConnect = NULL; + HINTERNET hConnect = nullptr; IHttpRequest *pRequest = m_pW3Context->GetRequest(); IHttpResponse *pResponse = m_pW3Context->GetResponse(); - IHttpConnection *pClientConnection = NULL; + IHttpConnection *pClientConnection = nullptr; PROTOCOL_CONFIG *pProtocol = &sm_ProtocolConfig; - SERVER_PROCESS *pServerProcess = NULL; + SERVER_PROCESS *pServerProcess = nullptr; USHORT cchHostName = 0; @@ -124,13 +124,13 @@ FORWARDING_HANDLER::ExecuteRequestHandler() // check connection pClientConnection = m_pW3Context->GetConnection(); - if (pClientConnection == NULL || + if (pClientConnection == nullptr || !pClientConnection->IsConnected()) { FAILURE(HRESULT_FROM_WIN32(WSAECONNRESET)); } - if (m_pApplication == NULL) + if (m_pApplication == nullptr) { FAILURE(E_INVALIDARG); } @@ -142,13 +142,13 @@ FORWARDING_HANDLER::ExecuteRequestHandler() FAILURE(hr); } - if (pServerProcess == NULL) + if (pServerProcess == nullptr) { fFailedToStartKestrel = TRUE; FAILURE(HRESULT_FROM_WIN32(ERROR_CREATE_FAILED)); } - if (pServerProcess->QueryWinHttpConnection() == NULL) + if (pServerProcess->QueryWinHttpConnection() == nullptr) { FAILURE(HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE)); } @@ -200,11 +200,11 @@ FORWARDING_HANDLER::ExecuteRequestHandler() // before staring a WinHTTP operation. // DBG_ASSERT(fRequestLocked); - DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == NULL); + DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == nullptr); TlsSetValue(g_dwTlsIndex, this); DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == this); - if (m_hRequest == NULL) + if (m_hRequest == nullptr) { FAILURE(HRESULT_FROM_WIN32(WSAECONNRESET)); } @@ -219,7 +219,7 @@ FORWARDING_HANDLER::ExecuteRequestHandler() // DWORD cbContentLength = 0; PCSTR pszContentLength = pRequest->GetHeader(HttpHeaderContentLength); - if (pszContentLength != NULL) + if (pszContentLength != nullptr) { cbContentLength = m_BytesToReceive = atol(pszContentLength); if (m_BytesToReceive == INFINITE) @@ -227,7 +227,7 @@ FORWARDING_HANDLER::ExecuteRequestHandler() FAILURE(HRESULT_FROM_WIN32(WSAECONNRESET)); } } - else if (pRequest->GetHeader(HttpHeaderTransferEncoding) != NULL) + else if (pRequest->GetHeader(HttpHeaderTransferEncoding) != nullptr) { m_BytesToReceive = INFINITE; } @@ -239,7 +239,7 @@ FORWARDING_HANDLER::ExecuteRequestHandler() // if (!WinHttpSetOption(m_hRequest, WINHTTP_OPTION_UPGRADE_TO_WEB_SOCKET, - NULL, + nullptr, 0)) { FINISHED(HRESULT_FROM_WIN32(GetLastError())); @@ -253,13 +253,13 @@ FORWARDING_HANDLER::ExecuteRequestHandler() { ANCMEvents::ANCM_REQUEST_FORWARD_START::RaiseEvent( m_pW3Context->GetTraceContext(), - NULL); + nullptr); } if (!WinHttpSendRequest(m_hRequest, m_pszHeaders, m_cchHeaders, - NULL, + nullptr, 0, cbContentLength, reinterpret_cast(static_cast(this)))) @@ -273,7 +273,7 @@ FORWARDING_HANDLER::ExecuteRequestHandler() { ANCMEvents::ANCM_REQUEST_FORWARD_FAIL::RaiseEvent( m_pW3Context->GetTraceContext(), - NULL, + nullptr, hr); } @@ -338,9 +338,9 @@ FORWARDING_HANDLER::ExecuteRequestHandler() if (fRequestLocked) { DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == this); - TlsSetValue(g_dwTlsIndex, NULL); + TlsSetValue(g_dwTlsIndex, nullptr); ReleaseSRWLockShared(&m_RequestLock); - DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == NULL); + DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == nullptr); } DereferenceRequestHandler(); @@ -382,8 +382,8 @@ REQUEST_NOTIFICATION_STATUS BOOL fClosed = FALSE; BOOL fWebSocketUpgraded = FALSE; - DBG_ASSERT(m_pW3Context != NULL); - __analysis_assume(m_pW3Context != NULL); + DBG_ASSERT(m_pW3Context != nullptr); + __analysis_assume(m_pW3Context != nullptr); // // Take a reference so that object does not go away as a result of @@ -391,7 +391,7 @@ REQUEST_NOTIFICATION_STATUS // ReferenceRequestHandler(); - if (sm_pTraceLog != NULL) + if (sm_pTraceLog != nullptr) { WriteRefTraceLogEx(sm_pTraceLog, m_cRefs, @@ -424,7 +424,7 @@ REQUEST_NOTIFICATION_STATUS // This should be the write completion of the 101 response. // m_pWebSocket = new WEBSOCKET_HANDLER(); - if (m_pWebSocket == NULL) + if (m_pWebSocket == nullptr) { FAILURE(E_OUTOFMEMORY); } @@ -447,7 +447,7 @@ REQUEST_NOTIFICATION_STATUS m_fHttpHandleInClose = TRUE; fClosed = WinHttpCloseHandle(m_hRequest); DBG_ASSERT(fClosed); - m_hRequest = NULL; + m_hRequest = nullptr; if (!fClosed) { @@ -490,7 +490,7 @@ REQUEST_NOTIFICATION_STATUS default: DBG_ASSERT(m_RequestStatus == FORWARDER_DONE); - if (m_hRequest == NULL && m_pWebSocket == NULL) + if (m_hRequest == nullptr && m_pWebSocket == nullptr) { // Request must have been done if (!m_fFinishRequest) @@ -567,7 +567,7 @@ REQUEST_NOTIFICATION_STATUS 0, strDescription.QueryStr(), strDescription.QuerySizeCCH(), - NULL); + nullptr); } else { @@ -598,17 +598,17 @@ REQUEST_NOTIFICATION_STATUS } } - if (m_pWebSocket != NULL && !m_fWebSocketHandleInClose) + if (m_pWebSocket != nullptr && !m_fWebSocketHandleInClose) { m_fWebSocketHandleInClose = TRUE; m_pWebSocket->TerminateRequest(); } - if (m_hRequest != NULL && !m_fHttpHandleInClose) + if (m_hRequest != nullptr && !m_fHttpHandleInClose) { m_fHttpHandleInClose = TRUE; WinHttpCloseHandle(m_hRequest); - m_hRequest = NULL; + m_hRequest = nullptr; } Finished: @@ -694,33 +694,33 @@ HRESULT VOID FORWARDING_HANDLER::StaticTerminate() { - if (sm_pResponseHeaderHash != NULL) + if (sm_pResponseHeaderHash != nullptr) { sm_pResponseHeaderHash->Clear(); delete sm_pResponseHeaderHash; - sm_pResponseHeaderHash = NULL; + sm_pResponseHeaderHash = nullptr; } - if (sm_pTraceLog != NULL) + if (sm_pTraceLog != nullptr) { DestroyRefTraceLog(sm_pTraceLog); - sm_pTraceLog = NULL; + sm_pTraceLog = nullptr; } - if (sm_pAlloc != NULL) + if (sm_pAlloc != nullptr) { delete sm_pAlloc; - sm_pAlloc = NULL; + sm_pAlloc = nullptr; } } // static void * FORWARDING_HANDLER::operator new(size_t) { - DBG_ASSERT(sm_pAlloc != NULL); - if (sm_pAlloc == NULL) + DBG_ASSERT(sm_pAlloc != nullptr); + if (sm_pAlloc == nullptr) { - return NULL; + return nullptr; } return sm_pAlloc->Alloc(); } @@ -728,8 +728,8 @@ void * FORWARDING_HANDLER::operator new(size_t) // static void FORWARDING_HANDLER::operator delete(void * pMemory) { - DBG_ASSERT(sm_pAlloc != NULL); - if (sm_pAlloc != NULL) + DBG_ASSERT(sm_pAlloc != nullptr); + if (sm_pAlloc != nullptr) { sm_pAlloc->Free(pMemory); } @@ -797,13 +797,13 @@ FORWARDING_HANDLER::GetHeaders( // iterate the list of headers to be removed and delete them from the request. // - while (ppHeadersToBeRemoved != NULL) + while (ppHeadersToBeRemoved != nullptr) { m_pW3Context->GetRequest()->DeleteHeader(ppHeadersToBeRemoved); ppHeadersToBeRemoved = mszMsAspNetCoreHeaders.Next(ppHeadersToBeRemoved); } - if (pServerProcess->QueryGuid() != NULL) + if (pServerProcess->QueryGuid() != nullptr) { RETURN_IF_FAILED(m_pW3Context->GetRequest()->SetHeader("MS-ASPNETCORE-TOKEN", pServerProcess->QueryGuid(), @@ -815,10 +815,10 @@ FORWARDING_HANDLER::GetHeaders( (_wcsicmp(m_pW3Context->GetUser()->GetAuthenticationType(), L"negotiate") == 0 || _wcsicmp(m_pW3Context->GetUser()->GetAuthenticationType(), L"ntlm") == 0)) { - if (m_pW3Context->GetUser()->GetPrimaryToken() != NULL && + if (m_pW3Context->GetUser()->GetPrimaryToken() != nullptr && m_pW3Context->GetUser()->GetPrimaryToken() != INVALID_HANDLE_VALUE) { - HANDLE hTargetTokenHandle = NULL; + HANDLE hTargetTokenHandle = nullptr; RETURN_IF_FAILED(pServerProcess->SetWindowsAuthToken(m_pW3Context->GetUser()->GetPrimaryToken(), &hTargetTokenHandle)); @@ -843,7 +843,7 @@ FORWARDING_HANDLER::GetHeaders( strTemp.Reset(); pszCurrentHeader = pRequest->GetHeader(pProtocol->QueryXForwardedForName()->QueryStr(), &cchCurrentHeader); - if (pszCurrentHeader != NULL) + if (pszCurrentHeader != nullptr) { RETURN_IF_FAILED(strTemp.Copy(pszCurrentHeader, cchCurrentHeader)); RETURN_IF_FAILED(strTemp.Append(", ", 2)); @@ -884,7 +884,7 @@ FORWARDING_HANDLER::GetHeaders( { const HTTP_SSL_INFO *pSslInfo = pRequest->GetRawHttpRequest()->pSslInfo; LPSTR pszScheme = "http"; - if (pSslInfo != NULL) + if (pSslInfo != nullptr) { pszScheme = "https"; } @@ -892,7 +892,7 @@ FORWARDING_HANDLER::GetHeaders( strTemp.Reset(); pszCurrentHeader = pRequest->GetHeader(pProtocol->QuerySslHeaderName()->QueryStr(), &cchCurrentHeader); - if (pszCurrentHeader != NULL) + if (pszCurrentHeader != nullptr) { RETURN_IF_FAILED(strTemp.Copy(pszCurrentHeader, cchCurrentHeader)); RETURN_IF_FAILED(strTemp.Append(", ", 2)); @@ -908,8 +908,8 @@ FORWARDING_HANDLER::GetHeaders( if (!pProtocol->QueryClientCertName()->IsEmpty()) { - if (pRequest->GetRawHttpRequest()->pSslInfo == NULL || - pRequest->GetRawHttpRequest()->pSslInfo->pClientCertInfo == NULL) + if (pRequest->GetRawHttpRequest()->pSslInfo == nullptr || + pRequest->GetRawHttpRequest()->pSslInfo->pClientCertInfo == nullptr) { pRequest->DeleteHeader(pProtocol->QueryClientCertName()->QueryStr()); } @@ -924,7 +924,7 @@ FORWARDING_HANDLER::GetHeaders( pRequest->GetRawHttpRequest()->pSslInfo->pClientCertInfo->CertEncodedSize, strTemp.QueryStr(), strTemp.QuerySize(), - NULL); + nullptr); strTemp.SyncWithBuffer(); RETURN_IF_FAILED(pRequest->SetHeader( @@ -963,7 +963,7 @@ FORWARDING_HANDLER::CreateWinHttpRequest( ) { HRESULT hr = S_OK; - PCWSTR pszVersion = NULL; + PCWSTR pszVersion = nullptr; PCSTR pszVerb; DWORD dwTimeout = INFINITE; STACK_STRU(strVerb, 32); @@ -976,7 +976,7 @@ FORWARDING_HANDLER::CreateWinHttpRequest( FINISHED_IF_FAILED(strVerb.CopyA(pszVerb)); //pszVersion = pProtocol->QueryVersion(); - if (pszVersion == NULL) + if (pszVersion == nullptr) { DWORD cchUnused; FINISHED_IF_FAILED(m_pW3Context->GetServerVariable( @@ -985,6 +985,8 @@ FORWARDING_HANDLER::CreateWinHttpRequest( &cchUnused)); } +#pragma warning(push) +#pragma warning(disable: 26477) // NULL usage via Windows header m_hRequest = WinHttpOpenRequest(hConnect, strVerb.QueryStr(), pstrUrl->QueryStr(), @@ -993,6 +995,7 @@ FORWARDING_HANDLER::CreateWinHttpRequest( WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_ESCAPE_DISABLE_QUERY | g_OptionalWinHttpFlags); +#pragma warning(pop) FINISHED_LAST_ERROR_IF_NULL (m_hRequest); @@ -1038,7 +1041,7 @@ FORWARDING_HANDLER::CreateWinHttpRequest( (WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS | WINHTTP_CALLBACK_FLAG_HANDLES | WINHTTP_CALLBACK_STATUS_SENDING_REQUEST), - NULL) == WINHTTP_INVALID_STATUS_CALLBACK); + 0) == WINHTTP_INVALID_STATUS_CALLBACK); FINISHED_IF_FAILED(GetHeaders(pProtocol, m_pApplication->QueryConfig()->QueryForwardWindowsAuthToken(), @@ -1060,7 +1063,7 @@ FORWARDING_HANDLER::OnWinHttpCompletion( ) { FORWARDING_HANDLER * pThis = static_cast(reinterpret_cast(dwContext)); - if (pThis == NULL) + if (pThis == nullptr) { //error happened, nothing can be done here return; @@ -1105,11 +1108,11 @@ None BOOL fAnotherCompletionExpected = FALSE; BOOL fDoPostCompletion = FALSE; BOOL fHandleClosing = (dwInternetStatus == WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING); - DWORD dwHandlers = 1; // defaullt for http handler + DWORD dwHandlers = 1; // default for http handler - DBG_ASSERT(m_pW3Context != NULL); - __analysis_assume(m_pW3Context != NULL); + DBG_ASSERT(m_pW3Context != nullptr); + __analysis_assume(m_pW3Context != nullptr); IHttpResponse * pResponse = m_pW3Context->GetResponse(); // Reference the request handler to prevent it from being released prematurely @@ -1117,14 +1120,14 @@ None UNREFERENCED_PARAMETER(dwStatusInformationLength); - if (sm_pTraceLog != NULL) + if (sm_pTraceLog != nullptr) { WriteRefTraceLogEx(sm_pTraceLog, m_cRefs, this, "FORWARDING_HANDLER::OnWinHttpCompletionInternal Enter", reinterpret_cast(static_cast(dwInternetStatus)), - NULL); + nullptr); } //FREB log @@ -1132,7 +1135,7 @@ None { ANCMEvents::ANCM_WINHTTP_CALLBACK::RaiseEvent( m_pW3Context->GetTraceContext(), - NULL, + nullptr, dwInternetStatus); } @@ -1149,11 +1152,11 @@ None if (TlsGetValue(g_dwTlsIndex) != this) { - DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == NULL); + DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == nullptr); if (m_RequestStatus != FORWARDER_RECEIVED_WEBSOCKET_RESPONSE) { - // Webscoket has already been guarded by critical section - // Only require exclisive lock for non-websocket scenario which has duplex channel + // Websocket has already been guarded by critical section + // Only require exclusive lock for non-websocket scenario which has duplex channel // Otherwise, there will be a deadlock AcquireLockExclusive(); fExclusiveLocked = TRUE; @@ -1195,7 +1198,7 @@ None if (m_RequestStatus == FORWARDER_RECEIVED_WEBSOCKET_RESPONSE) { fAnotherCompletionExpected = TRUE; - if (m_pWebSocket == NULL) + if (m_pWebSocket == nullptr) { goto Finished; } @@ -1280,14 +1283,14 @@ None { ANCMEvents::ANCM_REQUEST_FORWARD_END::RaiseEvent( m_pW3Context->GetTraceContext(), - NULL); + nullptr); } if (m_RequestStatus != FORWARDER_DONE) { hr = LOG_IF_FAILED(ERROR_CONNECTION_ABORTED); fClientError = m_fClientDisconnected; } - m_hRequest = NULL; + m_hRequest = nullptr; fAnotherCompletionExpected = FALSE; break; @@ -1301,14 +1304,14 @@ None // DBG_ASSERT(FALSE); hr = LOG_IF_FAILED(E_UNEXPECTED); - if (sm_pTraceLog != NULL) + if (sm_pTraceLog != nullptr) { WriteRefTraceLogEx(sm_pTraceLog, m_cRefs, this, "FORWARDING_HANDLER::OnWinHttpCompletionInternal Unexpected WinHTTP Status", reinterpret_cast(static_cast(dwInternetStatus)), - NULL); + nullptr); } break; } @@ -1372,7 +1375,7 @@ None 0, strDescription.QueryStr(), strDescription.QuerySizeCCH(), - NULL) == 0) + nullptr) == 0) { LoadString(g_hAspNetCoreModule, IDS_SERVER_ERROR, @@ -1396,7 +1399,7 @@ None { ANCMEvents::ANCM_REQUEST_FORWARD_FAIL::RaiseEvent( m_pW3Context->GetTraceContext(), - NULL, + nullptr, hr); } @@ -1421,10 +1424,10 @@ None RemoveRequest(); m_fFinishRequest = TRUE; fDoPostCompletion = TRUE; - if (m_pWebSocket != NULL) + if (m_pWebSocket != nullptr) { m_pWebSocket->Terminate(); - m_pWebSocket = NULL; + m_pWebSocket = nullptr; } } else if (m_RequestStatus == FORWARDER_DONE) @@ -1433,14 +1436,14 @@ None // Error path // RemoveRequest(); - if (m_hRequest != NULL && !m_fHttpHandleInClose) + if (m_hRequest != nullptr && !m_fHttpHandleInClose) { m_fHttpHandleInClose = TRUE; WinHttpCloseHandle(m_hRequest); - m_hRequest = NULL; + m_hRequest = nullptr; } - if (m_pWebSocket != NULL && !m_fWebSocketHandleInClose) + if (m_pWebSocket != nullptr && !m_fWebSocketHandleInClose) { m_fWebSocketHandleInClose = TRUE; m_pWebSocket->TerminateRequest(); @@ -1475,9 +1478,9 @@ None else if (fSharedLocked) { DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == this); - TlsSetValue(g_dwTlsIndex, NULL); + TlsSetValue(g_dwTlsIndex, nullptr); ReleaseSRWLockShared(&m_RequestLock); - DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == NULL); + DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == nullptr); } DereferenceRequestHandler(); @@ -1502,27 +1505,27 @@ FORWARDING_HANDLER::OnWinHttpCompletionSendRequestOrWriteComplete( // if (m_BytesToReceive > 0) { - if (m_pEntityBuffer == NULL) + if (m_pEntityBuffer == nullptr) { FINISHED_IF_NULL_ALLOC(m_pEntityBuffer = GetNewResponseBuffer( ENTITY_BUFFER_SIZE)); } - if (sm_pTraceLog != NULL) + if (sm_pTraceLog != nullptr) { WriteRefTraceLogEx(sm_pTraceLog, m_cRefs, this, "Calling ReadEntityBody", - NULL, - NULL); + nullptr, + nullptr); } hr = pRequest->ReadEntityBody( m_pEntityBuffer + 6, min(m_BytesToReceive, BUFFER_SIZE), TRUE, // fAsync - NULL, // pcbBytesReceived - NULL); // pfCompletionPending + nullptr, // pcbBytesReceived + nullptr); // pfCompletionPending if (hr == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF)) { DBG_ASSERT(m_BytesToReceive == 0 || @@ -1548,7 +1551,7 @@ FORWARDING_HANDLER::OnWinHttpCompletionSendRequestOrWriteComplete( if (!WinHttpWriteData(m_hRequest, "0\r\n\r\n", 5, - NULL)) + nullptr)) { FINISHED(HRESULT_FROM_WIN32(GetLastError())); //DereferenceForwardingHandler(); @@ -1577,7 +1580,7 @@ FORWARDING_HANDLER::OnWinHttpCompletionSendRequestOrWriteComplete( m_RequestStatus = FORWARDER_RECEIVING_RESPONSE; - FINISHED_LAST_ERROR_IF(!WinHttpReceiveResponse(hRequest, NULL)); + FINISHED_LAST_ERROR_IF(!WinHttpReceiveResponse(hRequest, nullptr)); *pfAnotherCompletionExpected = TRUE; Finished: @@ -1605,6 +1608,8 @@ FORWARDING_HANDLER::OnWinHttpCompletionStatusHeadersAvailable( // WinHttpQueryHeaders operates synchronously, // no need for taking reference. // +#pragma warning(push) +#pragma warning(disable: 26477) // NULL usage via Windows header dwHeaderSize = bufHeaderBuffer.QuerySize(); if (!WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_RAW_HEADERS_CRLF, @@ -1629,6 +1634,7 @@ FORWARDING_HANDLER::OnWinHttpCompletionStatusHeadersAvailable( &dwHeaderSize, WINHTTP_NO_HEADER_INDEX)); } +#pragma warning(pop) FINISHED_IF_FAILED(strHeaders.CopyW(reinterpret_cast(bufHeaderBuffer.QueryPtr()))); @@ -1664,8 +1670,8 @@ FORWARDING_HANDLER::OnWinHttpCompletionStatusHeadersAvailable( hr = m_pW3Context->GetResponse()->Flush( TRUE, TRUE, - NULL, - NULL); + nullptr, + nullptr); if (FAILED_LOG(hr)) { @@ -1726,7 +1732,7 @@ FORWARDING_HANDLER::OnWinHttpCompletionStatusDataAvailable( FINISHED_LAST_ERROR_IF(!WinHttpReadData(hRequest, m_pEntityBuffer, min(m_BytesToSend, BUFFER_SIZE), - NULL)); + nullptr)); *pfAnotherCompletionExpected = TRUE; @@ -1799,7 +1805,7 @@ FORWARDING_HANDLER::OnWinHttpCompletionStatusReadComplete( // FINISHED_IF_FAILED(pResponse->Flush(TRUE, // fAsync TRUE, // fMoreData - NULL)); // pcbSent + nullptr)); // pcbSent *pfAnotherCompletionExpected = TRUE; } @@ -1836,13 +1842,13 @@ FORWARDING_HANDLER::OnSendingRequest( RETURN_LAST_ERROR_IF(!WinHttpWriteData(m_hRequest, "0\r\n\r\n", 5, - NULL)); + nullptr)); } else { m_RequestStatus = FORWARDER_RECEIVING_RESPONSE; - RETURN_LAST_ERROR_IF(!WinHttpReceiveResponse(m_hRequest, NULL)); + RETURN_LAST_ERROR_IF(!WinHttpReceiveResponse(m_hRequest, nullptr)); } } else if (SUCCEEDED(hrCompletionStatus)) @@ -1904,7 +1910,7 @@ FORWARDING_HANDLER::OnSendingRequest( RETURN_LAST_ERROR_IF(!WinHttpWriteData(m_hRequest, m_pEntityBuffer + cbOffset, cbCompletion, - NULL)); + nullptr)); } else { @@ -1946,17 +1952,17 @@ FORWARDING_HANDLER::OnReceivingResponse( // // No buffering enabled. // - RETURN_LAST_ERROR_IF(!WinHttpQueryDataAvailable(m_hRequest, NULL)); + RETURN_LAST_ERROR_IF(!WinHttpQueryDataAvailable(m_hRequest, nullptr)); } else { // // Buffering enabled. // - if (m_pEntityBuffer == NULL) + if (m_pEntityBuffer == nullptr) { m_pEntityBuffer = GetNewResponseBuffer(min(m_BytesToSend, BUFFER_SIZE)); - if (m_pEntityBuffer == NULL) + if (m_pEntityBuffer == nullptr) { RETURN_HR(E_OUTOFMEMORY); } @@ -1965,7 +1971,7 @@ FORWARDING_HANDLER::OnReceivingResponse( RETURN_LAST_ERROR_IF(!WinHttpReadData(m_hRequest, m_pEntityBuffer, min(m_BytesToSend, BUFFER_SIZE), - NULL)); + nullptr)); } return S_OK; @@ -1981,15 +1987,15 @@ FORWARDING_HANDLER::GetNewResponseBuffer( !m_buffEntityBuffers.Resize( max(dwNeededSize, m_buffEntityBuffers.QuerySize() * 2))) { - return NULL; + return nullptr; } BYTE *pBuffer = (BYTE *)HeapAlloc(GetProcessHeap(), 0, // dwFlags dwBufferSize); - if (pBuffer == NULL) + if (pBuffer == nullptr) { - return NULL; + return nullptr; } m_buffEntityBuffers.QueryPtr()[m_cEntityBuffers] = pBuffer; @@ -2009,7 +2015,7 @@ FORWARDING_HANDLER::FreeResponseBuffers() pBuffers[i]); } m_cEntityBuffers = 0; - m_pEntityBuffer = NULL; + m_pEntityBuffer = nullptr; m_cBytesBuffered = 0; } @@ -2028,13 +2034,13 @@ FORWARDING_HANDLER::SetStatusAndHeaders( PCSTR pchEndofHeaderValue; BOOL fServerHeaderPresent = FALSE; - _ASSERT(pszHeaders != NULL); + _ASSERT(pszHeaders != nullptr); // // The first line is the status line // PSTR pchStatus = const_cast(strchr(pszHeaders, ' ')); - if (pchStatus == NULL) + if (pchStatus == nullptr) { return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); } @@ -2054,7 +2060,7 @@ FORWARDING_HANDLER::SetStatusAndHeaders( } pchStatus = strchr(pchStatus, ' '); - if (pchStatus == NULL) + if (pchStatus == nullptr) { return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); } @@ -2068,7 +2074,7 @@ FORWARDING_HANDLER::SetStatusAndHeaders( } pchNewline = strchr(pchStatus, '\n'); - if (pchNewline == NULL) + if (pchNewline == nullptr) { return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); } @@ -2096,7 +2102,7 @@ FORWARDING_HANDLER::SetStatusAndHeaders( strHeaderValue.QueryStr(), 0, S_OK, - NULL, + nullptr, TRUE)); } @@ -2114,7 +2120,7 @@ FORWARDING_HANDLER::SetStatusAndHeaders( // pchNewline = const_cast(strchr(pszHeaders + index, '\n')); - if (pchNewline == NULL) + if (pchNewline == nullptr) { return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); } @@ -2129,8 +2135,8 @@ FORWARDING_HANDLER::SetStatusAndHeaders( } DBG_ASSERT( - (pchColon != NULL) && (pchColon < pchNewline)); - if ((pchColon == NULL) || (pchColon >= pchNewline)) + (pchColon != nullptr) && (pchColon < pchNewline)); + if ((pchColon == nullptr) || (pchColon >= pchNewline)) { return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); } @@ -2265,7 +2271,7 @@ FORWARDING_HANDLER::DoReverseRewrite( ) { DBG_ASSERT(pResponse == m_pW3Context->GetResponse()); - BOOL fSecure = (m_pW3Context->GetRequest()->GetRawHttpRequest()->pSslInfo != NULL); + BOOL fSecure = (m_pW3Context->GetRequest()->GetRawHttpRequest()->pSslInfo != nullptr); STRA strTemp; PCSTR pszHeader; PCSTR pszStartHost; @@ -2277,7 +2283,7 @@ FORWARDING_HANDLER::DoReverseRewrite( // http[s]://host/url format // pszHeader = pResponse->GetHeader(HttpHeaderContentLocation); - if (pszHeader != NULL) + if (pszHeader != nullptr) { if (_strnicmp(pszHeader, "http://", 7) == 0) { @@ -2297,7 +2303,7 @@ FORWARDING_HANDLER::DoReverseRewrite( RETURN_IF_FAILED(strTemp.Copy(fSecure ? "https://" : "http://")); RETURN_IF_FAILED(strTemp.Append(m_pszOriginalHostHeader)); - if (pszEndHost != NULL) + if (pszEndHost != nullptr) { RETURN_IF_FAILED(strTemp.Append(pszEndHost)); } @@ -2310,7 +2316,7 @@ FORWARDING_HANDLER::DoReverseRewrite( Location: pszHeader = pResponse->GetHeader(HttpHeaderLocation); - if (pszHeader != NULL) + if (pszHeader != nullptr) { if (_strnicmp(pszHeader, "http://", 7) == 0) { @@ -2330,7 +2336,7 @@ FORWARDING_HANDLER::DoReverseRewrite( RETURN_IF_FAILED(strTemp.Copy(fSecure ? "https://" : "http://")); RETURN_IF_FAILED(strTemp.Append(m_pszOriginalHostHeader)); - if (pszEndHost != NULL) + if (pszEndHost != nullptr) { RETURN_IF_FAILED(strTemp.Append(pszEndHost)); } @@ -2356,7 +2362,7 @@ FORWARDING_HANDLER::DoReverseRewrite( pszHeader = pHeaders->pUnknownHeaders[i].pRawValue; pszStartHost = strchr(pszHeader, ';'); - while (pszStartHost != NULL) + while (pszStartHost != nullptr) { pszStartHost++; while (IsSpace(*pszStartHost)) @@ -2401,7 +2407,7 @@ FORWARDING_HANDLER::DoReverseRewrite( RETURN_IF_FAILED(strTemp.Append(pszEndHost)); pszHeader = (PCSTR)m_pW3Context->AllocateRequestMemory(strTemp.QueryCCH() + 1); - if (pszHeader == NULL) + if (pszHeader == nullptr) { RETURN_HR(E_OUTOFMEMORY); } @@ -2460,20 +2466,22 @@ FORWARDING_HANDLER::NotifyDisconnect() } } +_Acquires_exclusive_lock_(this->m_RequestLock) VOID FORWARDING_HANDLER::AcquireLockExclusive() { - DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == NULL); + DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == nullptr); AcquireSRWLockExclusive(&m_RequestLock); TlsSetValue(g_dwTlsIndex, this); DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == this); } +_Releases_exclusive_lock_(this->m_RequestLock) VOID FORWARDING_HANDLER::ReleaseLockExclusive() { DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == this); - TlsSetValue(g_dwTlsIndex, NULL); + TlsSetValue(g_dwTlsIndex, nullptr); ReleaseSRWLockExclusive(&m_RequestLock); - DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == NULL); + DBG_ASSERT(TlsGetValue(g_dwTlsIndex) == nullptr); } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.h b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.h index c564a7b4f03a..8e5c5c74d250 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.h @@ -77,9 +77,11 @@ class FORWARDING_HANDLER : public REQUEST_HANDLER private: + _Acquires_exclusive_lock_(this->m_RequestLock) VOID AcquireLockExclusive(); + _Releases_exclusive_lock_(this->m_RequestLock) VOID ReleaseLockExclusive(); diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/outprocessapplication.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/outprocessapplication.cpp index 897a97d17c05..b2f7fbd1dfff 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/outprocessapplication.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/outprocessapplication.cpp @@ -12,17 +12,17 @@ OUT_OF_PROCESS_APPLICATION::OUT_OF_PROCESS_APPLICATION( m_fWebSocketSupported(WEBSOCKET_STATUS::WEBSOCKET_UNKNOWN), m_pConfig(std::move(pConfig)) { - m_pProcessManager = NULL; + m_pProcessManager = nullptr; } OUT_OF_PROCESS_APPLICATION::~OUT_OF_PROCESS_APPLICATION() { SRWExclusiveLock lock(m_stopLock); - if (m_pProcessManager != NULL) + if (m_pProcessManager != nullptr) { m_pProcessManager->Shutdown(); m_pProcessManager->DereferenceProcessManager(); - m_pProcessManager = NULL; + m_pProcessManager = nullptr; } } @@ -30,7 +30,7 @@ HRESULT OUT_OF_PROCESS_APPLICATION::Initialize( ) { - if (m_pProcessManager == NULL) + if (m_pProcessManager == nullptr) { m_pProcessManager = new PROCESS_MANAGER(); RETURN_IF_FAILED(m_pProcessManager->Initialize()); @@ -52,7 +52,7 @@ OUT_OF_PROCESS_APPLICATION::StopInternal(bool fServerInitiated) { AppOfflineTrackingApplication::StopInternal(fServerInitiated); - if (m_pProcessManager != NULL) + if (m_pProcessManager != nullptr) { m_pProcessManager->Shutdown(); } @@ -63,7 +63,7 @@ OUT_OF_PROCESS_APPLICATION::CreateHandler( _In_ IHttpContext *pHttpContext, _Out_ IREQUEST_HANDLER **pRequestHandler) { - IREQUEST_HANDLER* pHandler = NULL; + IREQUEST_HANDLER* pHandler = nullptr; //add websocket check here if (m_fWebSocketSupported == WEBSOCKET_STATUS::WEBSOCKET_UNKNOWN) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/processmanager.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/processmanager.cpp index fdcc7210ad7d..07bdebf13833 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/processmanager.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/processmanager.cpp @@ -32,12 +32,12 @@ PROCESS_MANAGER::Initialize( m_dwRapidFailTickStart = GetTickCount(); - if( m_hNULHandle == NULL ) + if( m_hNULHandle == nullptr ) { SECURITY_ATTRIBUTES saAttr; saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; - saAttr.lpSecurityDescriptor = NULL; + saAttr.lpSecurityDescriptor = nullptr; m_hNULHandle = CreateFileW( L"NUL", FILE_WRITE_DATA, @@ -45,7 +45,7 @@ PROCESS_MANAGER::Initialize( &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, - NULL ); + nullptr ); RETURN_LAST_ERROR_IF( m_hNULHandle == INVALID_HANDLE_VALUE ); } @@ -82,7 +82,7 @@ PROCESS_MANAGER::GetProcess( for (DWORD i = 0; i < m_dwProcessesPerApplication; ++i) { - m_ppServerProcessList[i] = NULL; + m_ppServerProcessList[i] = nullptr; } } m_fServerProcessListReady = TRUE; @@ -97,7 +97,7 @@ PROCESS_MANAGER::GetProcess( dwProcessIndex = InterlockedIncrement(&m_dwRouteToProcessIndex); dwProcessIndex = dwProcessIndex % m_dwProcessesPerApplication; - if (m_ppServerProcessList[dwProcessIndex] != NULL && + if (m_ppServerProcessList[dwProcessIndex] != nullptr && m_ppServerProcessList[dwProcessIndex]->IsReady()) { *ppServerProcess = m_ppServerProcessList[dwProcessIndex]; @@ -106,12 +106,12 @@ PROCESS_MANAGER::GetProcess( } // should make the lock per process so that we can start processes simultaneously ? - if (m_ppServerProcessList[dwProcessIndex] == NULL || + if (m_ppServerProcessList[dwProcessIndex] == nullptr || !m_ppServerProcessList[dwProcessIndex]->IsReady()) { auto lock = SRWExclusiveLock(m_srwLock); - if (m_ppServerProcessList[dwProcessIndex] != NULL) + if (m_ppServerProcessList[dwProcessIndex] != nullptr) { if (!m_ppServerProcessList[dwProcessIndex]->IsReady()) { @@ -143,7 +143,7 @@ PROCESS_MANAGER::GetProcess( RETURN_HR(HRESULT_FROM_WIN32(ERROR_SERVER_DISABLED)); } - if (m_ppServerProcessList[dwProcessIndex] == NULL) + if (m_ppServerProcessList[dwProcessIndex] == nullptr) { pSelectedServerProcess = std::make_unique(); diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/processmanager.h b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/processmanager.h index 764e77d59563..119c5eb1366f 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/processmanager.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/processmanager.h @@ -53,12 +53,12 @@ class PROCESS_MANAGER for(DWORD i = 0; i < m_dwProcessesPerApplication; ++i ) { - if( m_ppServerProcessList != NULL && - m_ppServerProcessList[i] != NULL ) + if( m_ppServerProcessList != nullptr && + m_ppServerProcessList[i] != nullptr ) { m_ppServerProcessList[i]->SendSignal(); m_ppServerProcessList[i]->DereferenceServerProcess(); - m_ppServerProcessList[i] = NULL; + m_ppServerProcessList[i] = nullptr; } } @@ -107,8 +107,8 @@ class PROCESS_MANAGER } PROCESS_MANAGER() : - m_ppServerProcessList( NULL ), - m_hNULHandle( NULL ), + m_ppServerProcessList(nullptr), + m_hNULHandle(nullptr), m_cRapidFailCount( 0 ), m_dwProcessesPerApplication( 1 ), m_dwRouteToProcessIndex( 0 ), @@ -116,7 +116,7 @@ class PROCESS_MANAGER m_lStopping(0), m_cRefs( 1 ) { - m_ppServerProcessList = NULL; + m_ppServerProcessList = nullptr; m_fServerProcessListReady = FALSE; InitializeSRWLock( &m_srwLock ); } @@ -151,14 +151,14 @@ class PROCESS_MANAGER { for(DWORD i = 0; i < m_dwProcessesPerApplication; ++i ) { - if( m_ppServerProcessList != NULL && - m_ppServerProcessList[i] != NULL && + if( m_ppServerProcessList != nullptr && + m_ppServerProcessList[i] != nullptr && m_ppServerProcessList[i]->GetPort() == pServerProcess->GetPort() ) { // shutdown pServerProcess if not already shutdown. m_ppServerProcessList[i]->StopProcess(); m_ppServerProcessList[i]->DereferenceServerProcess(); - m_ppServerProcessList[i] = NULL; + m_ppServerProcessList[i] = nullptr; } } } @@ -170,13 +170,13 @@ class PROCESS_MANAGER { for(DWORD i = 0; i < m_dwProcessesPerApplication; ++i ) { - if( m_ppServerProcessList != NULL && - m_ppServerProcessList[i] != NULL ) + if( m_ppServerProcessList != nullptr && + m_ppServerProcessList[i] != nullptr) { // shutdown pServerProcess if not already shutdown. m_ppServerProcessList[i]->SendSignal(); m_ppServerProcessList[i]->DereferenceServerProcess(); - m_ppServerProcessList[i] = NULL; + m_ppServerProcessList[i] = nullptr; } } } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/responseheaderhash.h b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/responseheaderhash.h index 54f9c8295426..05b595f6bdcb 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/responseheaderhash.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/responseheaderhash.h @@ -73,10 +73,10 @@ class RESPONSE_HEADER_HASH: public HASH_TABLE PCSTR pszName ) { - HEADER_RECORD * pRecord = NULL; + HEADER_RECORD* pRecord = nullptr; FindKey(pszName, &pRecord); - if (pRecord != NULL) + if (pRecord != nullptr) { return pRecord->_ulHeaderIndex; } @@ -96,7 +96,7 @@ class RESPONSE_HEADER_HASH: public HASH_TABLE return sm_rgHeaders[ulIndex]._pszName; } - return NULL; + return nullptr; } private: diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/serverprocess.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/serverprocess.cpp index 52146c27d5cb..e1aaae6493a0 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/serverprocess.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/serverprocess.cpp @@ -135,13 +135,13 @@ SERVER_PROCESS::SetupListenPort( ) { HRESULT hr = S_OK; - ENVIRONMENT_VAR_ENTRY *pEntry = NULL; + ENVIRONMENT_VAR_ENTRY *pEntry = nullptr; *pfCriticalError = FALSE; pEnvironmentVarTable->FindKey(ASPNETCORE_PORT_ENV_STR, &pEntry); - if (pEntry != NULL) + if (pEntry != nullptr) { - if (pEntry->QueryValue() != NULL && pEntry->QueryValue()[0] != L'\0') + if (pEntry->QueryValue() != nullptr && pEntry->QueryValue()[0] != L'\0') { m_dwPort = (DWORD)_wtoi(pEntry->QueryValue()); if (m_dwPort >MAX_PORT || m_dwPort < MIN_PORT) @@ -161,7 +161,7 @@ SERVER_PROCESS::SetupListenPort( // pEnvironmentVarTable->DeleteKey(ASPNETCORE_PORT_ENV_STR); pEntry->Dereference(); - pEntry = NULL; + pEntry = nullptr; } } @@ -178,7 +178,7 @@ SERVER_PROCESS::SetupListenPort( } pEntry = new ENVIRONMENT_VAR_ENTRY(); - if (pEntry == NULL) + if (pEntry == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -192,10 +192,10 @@ SERVER_PROCESS::SetupListenPort( } Finished: - if (pEntry != NULL) + if (pEntry != nullptr) { pEntry->Dereference(); - pEntry = NULL; + pEntry = nullptr; } if (FAILED_LOG(hr)) @@ -252,20 +252,20 @@ SERVER_PROCESS::SetupAppToken( { HRESULT hr = S_OK; UUID logUuid; - PSTR pszLogUuid = NULL; + PSTR pszLogUuid = nullptr; BOOL fRpcStringAllocd = FALSE; RPC_STATUS rpcStatus; STRU strAppToken; - ENVIRONMENT_VAR_ENTRY* pEntry = NULL; + ENVIRONMENT_VAR_ENTRY* pEntry = nullptr; pEnvironmentVarTable->FindKey(ASPNETCORE_APP_TOKEN_ENV_STR, &pEntry); - if (pEntry != NULL) + if (pEntry != nullptr) { // user sets the environment variable m_straGuid.Reset(); hr = m_straGuid.CopyW(pEntry->QueryValue()); pEntry->Dereference(); - pEntry = NULL; + pEntry = nullptr; goto Finished; } else @@ -296,7 +296,7 @@ SERVER_PROCESS::SetupAppToken( } pEntry = new ENVIRONMENT_VAR_ENTRY(); - if (pEntry == NULL) + if (pEntry == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -315,12 +315,12 @@ SERVER_PROCESS::SetupAppToken( if (fRpcStringAllocd) { RpcStringFreeA((BYTE **)&pszLogUuid); - pszLogUuid = NULL; + pszLogUuid = nullptr; } - if (pEntry != NULL) + if (pEntry != nullptr) { pEntry->Dereference(); - pEntry = NULL; + pEntry = nullptr; } return hr; } @@ -333,12 +333,12 @@ SERVER_PROCESS::OutputEnvironmentVariables ) { HRESULT hr = S_OK; - LPWSTR pszEnvironmentVariables = NULL; - LPWSTR pszCurrentVariable = NULL; - LPWSTR pszNextVariable = NULL; - LPWSTR pszEqualChar = NULL; + LPWSTR pszEnvironmentVariables = nullptr; + LPWSTR pszCurrentVariable = nullptr; + LPWSTR pszNextVariable = nullptr; + LPWSTR pszEqualChar = nullptr; STRU strEnvVar; - ENVIRONMENT_VAR_ENTRY* pEntry = NULL; + ENVIRONMENT_VAR_ENTRY* pEntry = nullptr; DBG_ASSERT(pmszOutput); DBG_ASSERT(pEnvironmentVarTable); // We added some startup variables @@ -348,7 +348,7 @@ SERVER_PROCESS::OutputEnvironmentVariables pmszOutput->Reset(); pszEnvironmentVariables = GetEnvironmentStringsW(); - if (pszEnvironmentVariables == NULL) + if (pszEnvironmentVariables == nullptr) { hr = HRESULT_FROM_WIN32(ERROR_INVALID_ENVIRONMENT); goto Finished; @@ -358,14 +358,14 @@ SERVER_PROCESS::OutputEnvironmentVariables { pszNextVariable = pszCurrentVariable + wcslen(pszCurrentVariable) + 1; pszEqualChar = wcschr(pszCurrentVariable, L'='); - if (pszEqualChar != NULL) + if (pszEqualChar != nullptr) { if (FAILED_LOG(hr = strEnvVar.Copy(pszCurrentVariable, (DWORD)(pszEqualChar - pszCurrentVariable) + 1))) { goto Finished; } pEnvironmentVarTable->FindKey(strEnvVar.QueryStr(), &pEntry); - if (pEntry != NULL) + if (pEntry != nullptr) { // same env variable is defined in configuration, use it if (FAILED_LOG(hr = strEnvVar.Append(pEntry->QueryValue()))) @@ -377,7 +377,7 @@ SERVER_PROCESS::OutputEnvironmentVariables pEntry->Dereference(); pEnvironmentVarTable->DeleteKey(pEntry->QueryName()); strEnvVar.Reset(); - pEntry = NULL; + pEntry = nullptr; } else { @@ -386,7 +386,7 @@ SERVER_PROCESS::OutputEnvironmentVariables } else { - // env varaible is not well formated + // env variable is not well formatted hr = HRESULT_FROM_WIN32(ERROR_INVALID_ENVIRONMENT); goto Finished; } @@ -397,10 +397,10 @@ SERVER_PROCESS::OutputEnvironmentVariables pEnvironmentVarTable->Apply(ENVIRONMENT_VAR_HELPERS::CopyToMultiSz, pmszOutput); Finished: - if (pszEnvironmentVariables != NULL) + if (pszEnvironmentVariables != nullptr) { FreeEnvironmentStringsW(pszEnvironmentVariables); - pszEnvironmentVariables = NULL; + pszEnvironmentVariables = nullptr; } return hr; } @@ -411,11 +411,11 @@ SERVER_PROCESS::SetupCommandLine( ) { HRESULT hr = S_OK; - LPWSTR pszPath = NULL; - LPWSTR pszFullPath = NULL; + LPWSTR pszPath = nullptr; + LPWSTR pszFullPath = nullptr; STRU strRelativePath; DWORD dwBufferSize = 0; - FILE *file = NULL; + FILE *file = nullptr; DBG_ASSERT(pstrCommandLine); @@ -428,7 +428,7 @@ SERVER_PROCESS::SetupCommandLine( pszPath = m_ProcessPath.QueryStr(); - if ((wcsstr(pszPath, L":") == NULL) && (wcsstr(pszPath, L"%") == NULL)) + if ((wcsstr(pszPath, L":") == nullptr) && (wcsstr(pszPath, L"%") == nullptr)) { // let's check whether it is a relative path if (FAILED_LOG(hr = strRelativePath.Copy(m_struPhysicalPath.QueryStr())) || @@ -440,7 +440,7 @@ SERVER_PROCESS::SetupCommandLine( dwBufferSize = strRelativePath.QueryCCH() + 1; pszFullPath = new WCHAR[dwBufferSize]; - if (pszFullPath == NULL) + if (pszFullPath == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -448,13 +448,13 @@ SERVER_PROCESS::SetupCommandLine( if (_wfullpath(pszFullPath, strRelativePath.QueryStr(), - dwBufferSize) == NULL) + dwBufferSize) == nullptr) { hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); goto Finished; } - if ((file = _wfsopen(pszFullPath, L"r", _SH_DENYNO)) != NULL) + if ((file = _wfsopen(pszFullPath, L"r", _SH_DENYNO)) != nullptr) { fclose(file); pszPath = pszFullPath; @@ -469,7 +469,7 @@ SERVER_PROCESS::SetupCommandLine( } Finished: - if (pszFullPath != NULL) + if (pszFullPath != nullptr) { delete pszFullPath; } @@ -578,7 +578,7 @@ SERVER_PROCESS::PostStartCheck( m_dwListeningProcessId = m_dwChildProcessIds[i]; fProcessMatch = TRUE; - if (m_hChildProcessHandles[i] != NULL) + if (m_hChildProcessHandles[i] != nullptr) { if (fDebuggerAttached == FALSE && CheckRemoteDebuggerPresent(m_hChildProcessHandles[i], &fDebuggerAttached) == 0) @@ -664,10 +664,10 @@ SERVER_PROCESS::PostStartCheck( // ready to mark the server process ready but before this, // create and initialize the FORWARDER_CONNECTION // - if (m_pForwarderConnection == NULL) + if (m_pForwarderConnection == nullptr) { m_pForwarderConnection = new FORWARDER_CONNECTION(); - if (m_pForwarderConnection == NULL) + if (m_pForwarderConnection == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -694,10 +694,10 @@ SERVER_PROCESS::PostStartCheck( if (FAILED_LOG(hr)) { - if (m_pForwarderConnection != NULL) + if (m_pForwarderConnection != nullptr) { m_pForwarderConnection->DereferenceForwarderConnection(); - m_pForwarderConnection = NULL; + m_pForwarderConnection = nullptr; } if (!strEventMsg.IsEmpty()) @@ -716,13 +716,13 @@ SERVER_PROCESS::StartProcess( ) { HRESULT hr = S_OK; - PROCESS_INFORMATION processInformation = {0}; - STARTUPINFOW startupInfo = {0}; + PROCESS_INFORMATION processInformation = {}; + STARTUPINFOW startupInfo = {}; DWORD dwRetryCount = 2; // should we allow customer to config it DWORD dwCreationFlags = 0; MULTISZ mszNewEnvironment; - ENVIRONMENT_VAR_HASH *pHashTable = NULL; - PWSTR pStrStage = NULL; + ENVIRONMENT_VAR_HASH *pHashTable = nullptr; + PWSTR pStrStage = nullptr; BOOL fCriticalError = FALSE; std::map variables; @@ -815,10 +815,10 @@ SERVER_PROCESS::StartProcess( CREATE_NEW_PROCESS_GROUP; if (!CreateProcessW( - NULL, // applicationName + nullptr, // applicationName m_struCommandLine.QueryStr(), - NULL, // processAttr - NULL, // threadAttr + nullptr, // processAttr + nullptr, // threadAttr TRUE, // inheritHandles dwCreationFlags, mszNewEnvironment.QueryStr(), @@ -840,7 +840,7 @@ SERVER_PROCESS::StartProcess( goto Failure; } - if (m_hJobObject != NULL) + if (m_hJobObject != nullptr) { if (!AssignProcessToJobObject(m_hJobObject, m_hProcessHandle)) { @@ -900,17 +900,17 @@ SERVER_PROCESS::StartProcess( m_dwPort, dwRetryCount); - if (processInformation.hThread != NULL) + if (processInformation.hThread != nullptr) { CloseHandle(processInformation.hThread); - processInformation.hThread = NULL; + processInformation.hThread = nullptr; } - if (pHashTable != NULL) + if (pHashTable != nullptr) { pHashTable->Clear(); delete pHashTable; - pHashTable = NULL; + pHashTable = nullptr; } CleanUp(); @@ -919,24 +919,24 @@ SERVER_PROCESS::StartProcess( Finished: if (FAILED_LOG(hr) || m_fReady == FALSE) { - if (m_hStdErrWritePipe != NULL) + if (m_hStdErrWritePipe != nullptr) { if (m_hStdErrWritePipe != INVALID_HANDLE_VALUE) { CloseHandle(m_hStdErrWritePipe); } - m_hStdErrWritePipe = NULL; + m_hStdErrWritePipe = nullptr; } - if (m_hStdoutHandle != NULL) + if (m_hStdoutHandle != nullptr) { if (m_hStdoutHandle != INVALID_HANDLE_VALUE) { CloseHandle(m_hStdoutHandle); } - m_hStdoutHandle = NULL; + m_hStdoutHandle = nullptr; } if (m_fStdoutLogEnabled) @@ -964,7 +964,7 @@ SERVER_PROCESS::SetWindowsAuthToken( { HRESULT hr = S_OK; - if (m_hListeningProcessHandle != NULL && m_hListeningProcessHandle != INVALID_HANDLE_VALUE) + if (m_hListeningProcessHandle != nullptr && m_hListeningProcessHandle != INVALID_HANDLE_VALUE) { if (!DuplicateHandle( GetCurrentProcess(), hToken, @@ -999,7 +999,7 @@ SERVER_PROCESS::SetupStdHandles( saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; - saAttr.lpSecurityDescriptor = NULL; + saAttr.lpSecurityDescriptor = nullptr; if (!m_fEnableOutOfProcessConsoleRedirection) { @@ -1066,7 +1066,7 @@ SERVER_PROCESS::SetupStdHandles( &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, - NULL); + nullptr); if (m_hStdoutHandle == INVALID_HANDLE_VALUE) { @@ -1110,8 +1110,8 @@ SERVER_PROCESS::ReadStdErrHandle( LPVOID pContext ) { - auto pLoggingProvider = static_cast(pContext); - DBG_ASSERT(pLoggingProvider != NULL); + SERVER_PROCESS* pLoggingProvider = static_cast(pContext); + DBG_ASSERT(pLoggingProvider != nullptr); pLoggingProvider->ReadStdErrHandleInternal(); } @@ -1164,8 +1164,8 @@ SERVER_PROCESS::CheckIfServerIsUp( { HRESULT hr = S_OK; DWORD dwResult = ERROR_INSUFFICIENT_BUFFER; - MIB_TCPTABLE_OWNER_PID *pTCPInfo = NULL; - MIB_TCPROW_OWNER_PID *pOwner = NULL; + MIB_TCPTABLE_OWNER_PID *pTCPInfo = nullptr; + MIB_TCPROW_OWNER_PID *pOwner = nullptr; DWORD dwSize = 1000; // Initial size for pTCPInfo buffer int iResult = 0; SOCKET socketCheck = INVALID_SOCKET; @@ -1185,13 +1185,13 @@ SERVER_PROCESS::CheckIfServerIsUp( // New entries may be added by other processes before calling GetExtendedTcpTable dwSize += 200; - if (pTCPInfo != NULL) + if (pTCPInfo != nullptr) { HeapFree(GetProcessHeap(), 0, pTCPInfo); } pTCPInfo = (MIB_TCPTABLE_OWNER_PID*)HeapAlloc(GetProcessHeap(), 0, dwSize); - if (pTCPInfo == NULL) + if (pTCPInfo == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -1235,10 +1235,10 @@ SERVER_PROCESS::CheckIfServerIsUp( socketCheck = INVALID_SOCKET; } - if (pTCPInfo != NULL) + if (pTCPInfo != nullptr) { HeapFree(GetProcessHeap(), 0, pTCPInfo); - pTCPInfo = NULL; + pTCPInfo = nullptr; } return hr; @@ -1252,13 +1252,13 @@ SERVER_PROCESS::SendSignal( ) { HRESULT hr = S_OK; - HANDLE hThread = NULL; + HANDLE hThread = nullptr; ReferenceServerProcess(); m_hShutdownHandle = OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, FALSE, m_dwProcessId); - if (m_hShutdownHandle == NULL) + if (m_hShutdownHandle == nullptr) { // since we cannot open the process. let's terminate the process hr = HRESULT_FROM_WIN32(GetLastError()); @@ -1266,14 +1266,14 @@ SERVER_PROCESS::SendSignal( } hThread = CreateThread( - NULL, // default security attributes + nullptr, // default security attributes 0, // default stack size (LPTHREAD_START_ROUTINE)SendShutDownSignal, this, // thread function arguments 0, // default creation flags - NULL); // receive thread identifier + nullptr); // receive thread identifier - if (hThread == NULL) + if (hThread == nullptr) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Finished; @@ -1291,10 +1291,10 @@ SERVER_PROCESS::SendSignal( } // thread should already exit CloseHandle(hThread); - hThread = NULL; + hThread = nullptr; Finished: - if (hThread != NULL) + if (hThread != nullptr) { // if the send shutdown message thread is still running, terminate it DWORD dwThreadStatus = 0; @@ -1303,7 +1303,7 @@ SERVER_PROCESS::SendSignal( TerminateThread(hThread, STATUS_CONTROL_C_EXIT); } CloseHandle(hThread); - hThread = NULL; + hThread = nullptr; } if (FAILED_LOG(hr)) @@ -1311,10 +1311,10 @@ SERVER_PROCESS::SendSignal( TerminateBackendProcess(); } - if (m_hShutdownHandle != NULL && m_hShutdownHandle != INVALID_HANDLE_VALUE) + if (m_hShutdownHandle != nullptr && m_hShutdownHandle != INVALID_HANDLE_VALUE) { CloseHandle(m_hShutdownHandle); - m_hShutdownHandle = NULL; + m_hShutdownHandle = nullptr; } DereferenceServerProcess(); @@ -1334,28 +1334,28 @@ SERVER_PROCESS::StopProcess( m_pProcessManager->IncrementRapidFailCount(); - for (INT i=0; iNumberOfAssignedProcesses > processList->NumberOfProcessIdsInList || processList->NumberOfProcessIdsInList == 0)); @@ -1428,7 +1428,7 @@ SERVER_PROCESS::IsDebuggerIsAttached( goto Finished; } - if (processList == NULL || + if (processList == nullptr || (processList->NumberOfAssignedProcesses > processList->NumberOfProcessIdsInList || processList->NumberOfProcessIdsInList == 0)) { @@ -1454,10 +1454,10 @@ SERVER_PROCESS::IsDebuggerIsAttached( dwPid); BOOL returnValue = CheckRemoteDebuggerPresent(hProcess, &fDebuggerPresent); - if (hProcess != NULL) + if (hProcess != nullptr) { CloseHandle(hProcess); - hProcess = NULL; + hProcess = nullptr; } if (!returnValue) @@ -1474,7 +1474,7 @@ SERVER_PROCESS::IsDebuggerIsAttached( Finished: - if (processList != NULL) + if (processList != nullptr) { HeapFree(GetProcessHeap(), 0, processList); } @@ -1488,7 +1488,7 @@ SERVER_PROCESS::GetChildProcessHandles( ) { HRESULT hr = S_OK; - PJOBOBJECT_BASIC_PROCESS_ID_LIST processList = NULL; + PJOBOBJECT_BASIC_PROCESS_ID_LIST processList = nullptr; DWORD dwPid = 0; DWORD dwWorkerProcessPid = 0; DWORD cbNumBytes = 1024; @@ -1501,10 +1501,10 @@ SERVER_PROCESS::GetChildProcessHandles( { dwError = NO_ERROR; - if (processList != NULL) + if (processList != nullptr) { HeapFree(GetProcessHeap(), 0, processList); - processList = NULL; + processList = nullptr; // resize cbNumBytes = cbNumBytes * 2; @@ -1515,7 +1515,7 @@ SERVER_PROCESS::GetChildProcessHandles( 0, cbNumBytes ); - if (processList == NULL) + if (processList == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -1528,7 +1528,7 @@ SERVER_PROCESS::GetChildProcessHandles( JobObjectBasicProcessIdList, processList, cbNumBytes, - NULL)) + nullptr)) { dwError = GetLastError(); if (dwError != ERROR_MORE_DATA) @@ -1539,7 +1539,7 @@ SERVER_PROCESS::GetChildProcessHandles( } } while (dwRetries++ < 5 && - processList != NULL && + processList != nullptr && (processList->NumberOfAssignedProcesses > processList->NumberOfProcessIdsInList || processList->NumberOfProcessIdsInList == 0)); if (dwError == ERROR_MORE_DATA) @@ -1549,7 +1549,7 @@ SERVER_PROCESS::GetChildProcessHandles( goto Finished; } - if (processList == NULL || (processList->NumberOfAssignedProcesses > processList->NumberOfProcessIdsInList || processList->NumberOfProcessIdsInList == 0)) + if (processList == nullptr || (processList->NumberOfAssignedProcesses > processList->NumberOfProcessIdsInList || processList->NumberOfProcessIdsInList == 0)) { hr = HRESULT_FROM_WIN32(ERROR_PROCESS_ABORTED); // some error @@ -1580,7 +1580,7 @@ SERVER_PROCESS::GetChildProcessHandles( Finished: - if (processList != NULL) + if (processList != nullptr) { HeapFree(GetProcessHeap(), 0, processList); } @@ -1594,8 +1594,8 @@ SERVER_PROCESS::StopAllProcessesInJobObject( ) { HRESULT hr = S_OK; - PJOBOBJECT_BASIC_PROCESS_ID_LIST processList = NULL; - HANDLE hProcess = NULL; + PJOBOBJECT_BASIC_PROCESS_ID_LIST processList = nullptr; + HANDLE hProcess = nullptr; DWORD dwWorkerProcessPid = 0; DWORD cbNumBytes = 1024; DWORD dwRetries = 0; @@ -1604,10 +1604,10 @@ SERVER_PROCESS::StopAllProcessesInJobObject( do { - if (processList != NULL) + if (processList != nullptr) { HeapFree(GetProcessHeap(), 0, processList); - processList = NULL; + processList = nullptr; // resize cbNumBytes = cbNumBytes * 2; @@ -1618,7 +1618,7 @@ SERVER_PROCESS::StopAllProcessesInJobObject( 0, cbNumBytes ); - if (processList == NULL) + if (processList == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -1631,7 +1631,7 @@ SERVER_PROCESS::StopAllProcessesInJobObject( JobObjectBasicProcessIdList, processList, cbNumBytes, - NULL)) + nullptr)) { DWORD dwError = GetLastError(); if (dwError != ERROR_MORE_DATA) @@ -1642,10 +1642,10 @@ SERVER_PROCESS::StopAllProcessesInJobObject( } } while (dwRetries++ < 5 && - processList != NULL && + processList != nullptr && (processList->NumberOfAssignedProcesses > processList->NumberOfProcessIdsInList || processList->NumberOfProcessIdsInList == 0)); - if (processList == NULL || (processList->NumberOfAssignedProcesses > processList->NumberOfProcessIdsInList || processList->NumberOfProcessIdsInList == 0)) + if (processList == nullptr || (processList->NumberOfAssignedProcesses > processList->NumberOfProcessIdsInList || processList->NumberOfProcessIdsInList == 0)) { hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); // some error @@ -1659,7 +1659,7 @@ SERVER_PROCESS::StopAllProcessesInJobObject( hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, (DWORD)processList->ProcessIdList[i]); - if (hProcess != NULL) + if (hProcess != nullptr) { if (!TerminateProcess(hProcess, 1)) { @@ -1670,10 +1670,10 @@ SERVER_PROCESS::StopAllProcessesInJobObject( WaitForSingleObject(hProcess, INFINITE); } - if (hProcess != NULL) + if (hProcess != nullptr) { CloseHandle(hProcess); - hProcess = NULL; + hProcess = nullptr; } } } @@ -1681,7 +1681,7 @@ SERVER_PROCESS::StopAllProcessesInJobObject( Finished: - if (processList != NULL) + if (processList != nullptr) { HeapFree(GetProcessHeap(), 0, processList); } @@ -1691,20 +1691,20 @@ SERVER_PROCESS::StopAllProcessesInJobObject( SERVER_PROCESS::SERVER_PROCESS() : m_cRefs(1), - m_hProcessHandle(NULL), - m_hProcessWaitHandle(NULL), + m_hProcessHandle(nullptr), + m_hProcessWaitHandle(nullptr), m_dwProcessId(0), m_cChildProcess(0), m_fReady(FALSE), m_lStopping(0L), - m_hStdoutHandle(NULL), + m_hStdoutHandle(nullptr), m_fStdoutLogEnabled(FALSE), - m_hJobObject(NULL), - m_pForwarderConnection(NULL), + m_hJobObject(nullptr), + m_pForwarderConnection(nullptr), m_dwListeningProcessId(0), - m_hListeningProcessHandle(NULL), - m_hShutdownHandle(NULL), - m_hStdErrWritePipe(NULL), + m_hListeningProcessHandle(nullptr), + m_hShutdownHandle(nullptr), + m_hStdErrWritePipe(nullptr), m_hReadThread(nullptr), m_randomGenerator(std::random_device()()) { @@ -1713,75 +1713,75 @@ SERVER_PROCESS::SERVER_PROCESS() : for (INT i=0; iDereferenceForwarderConnection(); - m_pForwarderConnection = NULL; + m_pForwarderConnection = nullptr; } } @@ -1792,17 +1792,17 @@ SERVER_PROCESS::~SERVER_PROCESS() CleanUp(); - // no need to free m_pEnvironmentVarTable, as it references to - // the same hash table hold by configuration. - // the hashtable memory will be freed once onfiguration got recycled + // no need to free m_pEnvironmentVarTable, as it references + // the same hash table held by configuration. + // the hashtable memory will be freed once configuration gets recycled - if (m_pProcessManager != NULL) + if (m_pProcessManager != nullptr) { m_pProcessManager->DereferenceProcessManager(); - m_pProcessManager = NULL; + m_pProcessManager = nullptr; } - if (m_hStdErrWritePipe != NULL) + if (m_hStdErrWritePipe != nullptr) { if (m_hStdErrWritePipe != INVALID_HANDLE_VALUE) { @@ -1810,7 +1810,7 @@ SERVER_PROCESS::~SERVER_PROCESS() CloseHandle(m_hStdErrWritePipe); } - m_hStdErrWritePipe = NULL; + m_hStdErrWritePipe = nullptr; } // Forces ReadFile to cancel, causing the read loop to complete. @@ -1845,13 +1845,13 @@ SERVER_PROCESS::~SERVER_PROCESS() m_hReadThread = nullptr; } - if (m_hStdoutHandle != NULL) + if (m_hStdoutHandle != nullptr) { if (m_hStdoutHandle != INVALID_HANDLE_VALUE) { CloseHandle(m_hStdoutHandle); } - m_hStdoutHandle = NULL; + m_hStdoutHandle = nullptr; } if (m_fStdoutLogEnabled) @@ -1896,9 +1896,9 @@ SERVER_PROCESS::RegisterProcessWait( HRESULT hr = S_OK; NTSTATUS status = 0; - _ASSERT(phWaitHandle != NULL && *phWaitHandle == NULL); + _ASSERT(phWaitHandle != nullptr && *phWaitHandle == nullptr); - *phWaitHandle = NULL; + *phWaitHandle = nullptr; // wait thread will dereference. ReferenceServerProcess(); @@ -1922,7 +1922,7 @@ SERVER_PROCESS::RegisterProcessWait( if (FAILED_LOG(hr)) { - *phWaitHandle = NULL; + *phWaitHandle = nullptr; DereferenceServerProcess(); } @@ -1960,9 +1960,9 @@ HRESULT SERVER_PROCESS::SendShutdownHttpMessage( VOID ) { HRESULT hr = S_OK; - HINTERNET hSession = NULL; - HINTERNET hConnect = NULL; - HINTERNET hRequest = NULL; + HINTERNET hSession = nullptr; + HINTERNET hConnect = nullptr; + HINTERNET hRequest = nullptr; STACK_STRU(strHeaders, 256); STRU strAppToken; @@ -1970,13 +1970,16 @@ SERVER_PROCESS::SendShutdownHttpMessage( VOID ) DWORD dwStatusCode = 0; DWORD dwSize = sizeof(dwStatusCode); +#pragma warning(push) +#pragma warning(disable: 26477) // NULL usage via Windows header hSession = WinHttpOpen(L"", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); +#pragma warning(pop) - if (hSession == NULL) + if (hSession == nullptr) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Finished; @@ -1987,7 +1990,7 @@ SERVER_PROCESS::SendShutdownHttpMessage( VOID ) (USHORT)m_dwPort, 0); - if (hConnect == NULL) + if (hConnect == nullptr) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Finished; @@ -2001,15 +2004,18 @@ SERVER_PROCESS::SendShutdownHttpMessage( VOID ) } strUrl.Append(L"/iisintegration"); +#pragma warning(push) +#pragma warning(disable: 26477) // NULL usage via Windows header hRequest = WinHttpOpenRequest(hConnect, L"POST", strUrl.QueryStr(), - NULL, + nullptr, WINHTTP_NO_REFERER, - NULL, + nullptr, 0); +#pragma warning(pop) - if (hRequest == NULL) + if (hRequest == nullptr) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Finished; @@ -2035,6 +2041,8 @@ SERVER_PROCESS::SendShutdownHttpMessage( VOID ) goto Finished; } +#pragma warning(push) +#pragma warning(disable: 26477) // NULL usage via Windows header if (!WinHttpSendRequest(hRequest, strHeaders.QueryStr(), // pwszHeaders strHeaders.QueryCCH(), // dwHeadersLength @@ -2046,13 +2054,16 @@ SERVER_PROCESS::SendShutdownHttpMessage( VOID ) hr = HRESULT_FROM_WIN32(GetLastError()); goto Finished; } +#pragma warning(pop) - if (!WinHttpReceiveResponse(hRequest , NULL)) + if (!WinHttpReceiveResponse(hRequest , nullptr)) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Finished; } +#pragma warning(push) +#pragma warning(disable: 26477) // NULL usage via Windows header if (!WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, WINHTTP_HEADER_NAME_BY_INDEX, @@ -2063,6 +2074,7 @@ SERVER_PROCESS::SendShutdownHttpMessage( VOID ) hr = HRESULT_FROM_WIN32(GetLastError()); goto Finished; } +#pragma warning(pop) if (dwStatusCode != 202) { @@ -2081,17 +2093,17 @@ SERVER_PROCESS::SendShutdownHttpMessage( VOID ) if (hRequest) { WinHttpCloseHandle(hRequest); - hRequest = NULL; + hRequest = nullptr; } if (hConnect) { WinHttpCloseHandle(hConnect); - hConnect = NULL; + hConnect = nullptr; } if (hSession) { WinHttpCloseHandle(hSession); - hSession = NULL; + hSession = nullptr; } return hr; } @@ -2124,7 +2136,7 @@ SERVER_PROCESS::SendShutDownSignalInternal( // failed to send shutdown http message // try send ctrl signal // - HWND hCurrentConsole = NULL; + HWND hCurrentConsole = nullptr; BOOL fFreeConsole = FALSE; hCurrentConsole = GetConsoleWindow(); if (hCurrentConsole) @@ -2169,7 +2181,7 @@ SERVER_PROCESS::TerminateBackendProcess( if (InterlockedCompareExchange(&m_lStopping, 1L, 0L) == 0L) { // backend process will be terminated, remove the waitcallback - if (m_hProcessWaitHandle != NULL) + if (m_hProcessWaitHandle != nullptr) { UnregisterWait(m_hProcessWaitHandle); @@ -2177,14 +2189,14 @@ SERVER_PROCESS::TerminateBackendProcess( // need to dereference the object otherwise memory leak DereferenceServerProcess(); - m_hProcessWaitHandle = NULL; + m_hProcessWaitHandle = nullptr; } // cannot gracefully shutdown or timeout, terminate the process - if (m_hProcessHandle != NULL && m_hProcessHandle != INVALID_HANDLE_VALUE) + if (m_hProcessHandle != nullptr && m_hProcessHandle != INVALID_HANDLE_VALUE) { TerminateProcess(m_hProcessHandle, 0); - m_hProcessHandle = NULL; + m_hProcessHandle = nullptr; } // log a warning for ungraceful shutdown diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/url_utility.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/url_utility.cpp index 64118b61b6fe..ce3959adc54f 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/url_utility.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/url_utility.cpp @@ -66,7 +66,7 @@ Return Value: // Find the 3rd slash corresponding to the url // LPCWSTR pszSlash = wcschr(pszDestinationUrl, L'/'); - if (pszSlash == NULL) + if (pszSlash == nullptr) { RETURN_IF_FAILED(pstrUrl->Copy(L"/", 1)); RETURN_IF_FAILED(pstrDestination->Copy(pszDestinationUrl)); @@ -81,14 +81,6 @@ Return Value: return S_OK; } -// Change a hexadecimal digit to its numerical equivalent -#define TOHEX( ch ) \ - ((ch) > L'9' ? \ - (ch) >= L'a' ? \ - (ch) - L'a' + 10 : \ - (ch) - L'A' + 10 \ - : (ch) - L'0') - HRESULT URL_UTILITY::EscapeAbsPath( IHttpRequest * pRequest, @@ -96,8 +88,8 @@ URL_UTILITY::EscapeAbsPath( ) { STRU strAbsPath; - LPCWSTR pszAbsPath = NULL; - LPCWSTR pszFindStr = NULL; + LPCWSTR pszAbsPath = nullptr; + LPCWSTR pszFindStr = nullptr; RETURN_IF_FAILED(strAbsPath.Copy( pRequest->GetRawHttpRequest()->CookedUrl.pAbsPath, pRequest->GetRawHttpRequest()->CookedUrl.AbsPathLength / sizeof(WCHAR) )); @@ -105,7 +97,7 @@ URL_UTILITY::EscapeAbsPath( pszAbsPath = strAbsPath.QueryStr(); pszFindStr = wcschr(pszAbsPath, L'?'); - while(pszFindStr != NULL) + while(pszFindStr != nullptr) { RETURN_IF_FAILED(strEscapedUrl->Append( pszAbsPath, pszFindStr - pszAbsPath)); RETURN_IF_FAILED(strEscapedUrl->Append(L"%3F")); diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/websockethandler.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/websockethandler.cpp index ecd97737fe40..91dbdca04d21 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/websockethandler.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/websockethandler.cpp @@ -37,10 +37,10 @@ LIST_ENTRY WEBSOCKET_HANDLER::sm_RequestsListHead; TRACE_LOG * WEBSOCKET_HANDLER::sm_pTraceLog; WEBSOCKET_HANDLER::WEBSOCKET_HANDLER() : - _pHttpContext(NULL), - _pWebSocketContext(NULL), - _hWebSocketRequest(NULL), - _pHandler(NULL), + _pHttpContext(nullptr), + _pWebSocketContext(nullptr), + _hWebSocketRequest(nullptr), + _pHandler(nullptr), _dwOutstandingIo(0), _fCleanupInProgress(FALSE), _fIndicateCompletionToIis(FALSE), @@ -64,18 +64,18 @@ WEBSOCKET_HANDLER::Terminate( RemoveRequest(); _fCleanupInProgress = TRUE; - if (_pHttpContext != NULL) + if (_pHttpContext != nullptr) { _pHttpContext->CancelIo(); - _pHttpContext = NULL; + _pHttpContext = nullptr; } if (_hWebSocketRequest) { WinHttpCloseHandle(_hWebSocketRequest); - _hWebSocketRequest = NULL; + _hWebSocketRequest = nullptr; } - _pWebSocketContext = NULL; + _pWebSocketContext = nullptr; DeleteCriticalSection(&_RequestLock); delete this; @@ -129,7 +129,7 @@ WEBSOCKET_HANDLER::StaticTerminate( if (sm_pTraceLog) { DestroyRefTraceLog(sm_pTraceLog); - sm_pTraceLog = NULL; + sm_pTraceLog = nullptr; } } @@ -220,14 +220,14 @@ WEBSOCKET_HANDLER::IndicateCompletionToIIS( // Make sure no pending IO as there is no IIS websocket cancelation, // any unexpected callback will lead to AV. Revisit it once CanelOutGoingIO works // - if (_hWebSocketRequest != NULL && _dwOutstandingIo == 0) + if (_hWebSocketRequest != nullptr && _dwOutstandingIo == 0) { LOG_TRACE(L"WEBSOCKET_HANDLER::IndicateCompletionToIIS"); _pHandler->SetStatus(FORWARDER_DONE); _fHandleClosed = TRUE; WinHttpCloseHandle(_hWebSocketRequest); - _hWebSocketRequest = NULL; + _hWebSocketRequest = nullptr; } } @@ -279,7 +279,7 @@ Routine Description: _pWebSocketContext = (IWebSocketContext *) _pHttpContext-> GetNamedContextContainer()->GetNamedContext(IIS_WEBSOCKET); - if ( _pWebSocketContext == NULL ) + if ( _pWebSocketContext == nullptr ) { hr = HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ); goto Finished; @@ -292,7 +292,7 @@ Routine Description: hRequest, (DWORD_PTR) pHandler); - if (_hWebSocketRequest == NULL) + if (_hWebSocketRequest == nullptr) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Finished; @@ -394,7 +394,7 @@ Routine Description: &fClose, OnReadIoCompletion, this, - NULL); + nullptr); if (FAILED_LOG(hr)) { DecrementOutstandingIo(); @@ -428,8 +428,8 @@ Routine Description: _hWebSocketRequest, &_WinHttpReceiveBuffer, RECEIVE_BUFFER_SIZE, - NULL, - NULL); + nullptr, + nullptr); if (dwError != NO_ERROR) { @@ -509,15 +509,15 @@ Routine Description: hr = _pWebSocketContext->SendConnectionClose( TRUE, uStatus, - uStatus == 1005 ? NULL : strCloseReason.QueryStr(), + uStatus == 1005 ? nullptr : strCloseReason.QueryStr(), OnWriteIoCompletion, this, - NULL); + nullptr); } else { // - // Get equivalant flags for IIS API from buffer type. + // Get equivalent flags for IIS API from buffer type. // WINHTTP_HELPER::GetFlagsFromBufferType(eBufferType, @@ -538,7 +538,7 @@ Routine Description: fFinalFragment, OnWriteIoCompletion, this, - NULL); + nullptr); } if (FAILED_LOG(hr)) @@ -607,7 +607,7 @@ Routine Description: dwError = WINHTTP_HELPER::sm_pfnWinHttpWebSocketShutdown( _hWebSocketRequest, uStatus, - strCloseReason.QueryCCH() == 0 ? NULL : (PVOID) strCloseReason.QueryStr(), + strCloseReason.QueryCCH() == 0 ? nullptr : (PVOID) strCloseReason.QueryStr(), strCloseReason.QueryCCH()); if (dwError == ERROR_IO_PENDING) @@ -638,7 +638,7 @@ Routine Description: dwError = WINHTTP_HELPER::sm_pfnWinHttpWebSocketSend( _hWebSocketRequest, eBufferType, - cbData == 0 ? NULL : &_IisReceiveBuffer, + cbData == 0 ? nullptr : &_IisReceiveBuffer, cbData ); } @@ -1099,23 +1099,24 @@ Routine Description: if (reason == ClientDisconnect || reason == ServerStateUnavailable) { // - // Calling shutdown to notify the backend about disonnect + // Calling shutdown to notify the backend about disconnect // WINHTTP_HELPER::sm_pfnWinHttpWebSocketShutdown( _hWebSocketRequest, - 1011, // indicate that a server is terminating the connection because it encountered - // an unexpected condition that prevent it from fulfilling the request - NULL, // Reason - 0); // length og Reason + 1011, // indicate that a server is terminating the connection because it encountered + // an unexpected condition that prevent it from fulfilling the request + nullptr, // Reason + 0); // length of Reason } if (reason == ServerDisconnect || reason == ServerStateUnavailable) { _pHttpContext->CancelIo(); + // - // CancelIo sometime may not be able to cannel pending websocket IO - // ResetConnection to force IISWebsocket module to release the pipeline + // CancelIo sometimes may not be able to cancel pending websocket IO. + // ResetConnection to force IISWebsocket module to release the pipeline. // _pHttpContext->GetResponse()->ResetConnection(); } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.cpp index 8f6c5d37204e..1d0bbe742350 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.cpp @@ -34,27 +34,27 @@ WINHTTP_HELPER::StaticInitialize( } HMODULE hWinHttp = GetModuleHandleA("winhttp.dll"); - RETURN_LAST_ERROR_IF (hWinHttp == NULL); + RETURN_LAST_ERROR_IF (hWinHttp == nullptr); sm_pfnWinHttpWebSocketCompleteUpgrade = (PFN_WINHTTP_WEBSOCKET_COMPLETE_UPGRADE) GetProcAddress(hWinHttp, "WinHttpWebSocketCompleteUpgrade"); - RETURN_LAST_ERROR_IF (sm_pfnWinHttpWebSocketCompleteUpgrade == NULL); + RETURN_LAST_ERROR_IF (sm_pfnWinHttpWebSocketCompleteUpgrade == nullptr); sm_pfnWinHttpWebSocketQueryCloseStatus = (PFN_WINHTTP_WEBSOCKET_QUERY_CLOSE_STATUS) GetProcAddress(hWinHttp, "WinHttpWebSocketQueryCloseStatus"); - RETURN_LAST_ERROR_IF (sm_pfnWinHttpWebSocketQueryCloseStatus == NULL); + RETURN_LAST_ERROR_IF (sm_pfnWinHttpWebSocketQueryCloseStatus == nullptr); sm_pfnWinHttpWebSocketReceive = (PFN_WINHTTP_WEBSOCKET_RECEIVE) GetProcAddress(hWinHttp, "WinHttpWebSocketReceive"); - RETURN_LAST_ERROR_IF (sm_pfnWinHttpWebSocketReceive == NULL); + RETURN_LAST_ERROR_IF (sm_pfnWinHttpWebSocketReceive == nullptr); sm_pfnWinHttpWebSocketSend = (PFN_WINHTTP_WEBSOCKET_SEND) GetProcAddress(hWinHttp, "WinHttpWebSocketSend"); - RETURN_LAST_ERROR_IF (sm_pfnWinHttpWebSocketSend == NULL); + RETURN_LAST_ERROR_IF (sm_pfnWinHttpWebSocketSend == nullptr); sm_pfnWinHttpWebSocketShutdown = (PFN_WINHTTP_WEBSOCKET_SHUTDOWN) GetProcAddress(hWinHttp, "WinHttpWebSocketShutdown"); - RETURN_LAST_ERROR_IF (sm_pfnWinHttpWebSocketShutdown == NULL); + RETURN_LAST_ERROR_IF (sm_pfnWinHttpWebSocketShutdown == nullptr); return S_OK; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.cpp b/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.cpp index 4f0229dc5c3c..b56414041d33 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.cpp @@ -99,7 +99,7 @@ FILE_WATCHER::Create( (LPTHREAD_START_ROUTINE)ChangeNotificationThread, this, 0, - NULL)); + nullptr)); if (pszDirectoryToMonitor == nullptr || pszFileNameToMonitor == nullptr || @@ -128,7 +128,7 @@ FILE_WATCHER::Create( nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, - NULL); + nullptr); RETURN_LAST_ERROR_IF(_hDirectory == INVALID_HANDLE_VALUE); @@ -475,7 +475,7 @@ FILE_WATCHER::StopMonitor() LOG_INFO(L"Stopping file watching."); // Signal the file watcher thread to exit - PostQueuedCompletionStatus(m_hCompletionPort, 0, FILE_WATCHER_SHUTDOWN_KEY, NULL); + PostQueuedCompletionStatus(m_hCompletionPort, 0, FILE_WATCHER_SHUTDOWN_KEY, nullptr); WaitForWatcherThreadExit(); if (m_fShadowCopyEnabled) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.cpp b/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.cpp index c32bc51ced79..a77d479a2b67 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.cpp @@ -11,10 +11,10 @@ REQUESTHANDLER_CONFIG::~REQUESTHANDLER_CONFIG() { - if (m_ppStrArguments != NULL) + if (m_ppStrArguments != nullptr) { delete[] m_ppStrArguments; - m_ppStrArguments = NULL; + m_ppStrArguments = nullptr; } } @@ -27,19 +27,19 @@ REQUESTHANDLER_CONFIG::CreateRequestHandlerConfig( ) { HRESULT hr = S_OK; - REQUESTHANDLER_CONFIG *pRequestHandlerConfig = NULL; + REQUESTHANDLER_CONFIG *pRequestHandlerConfig = nullptr; STRU struHostFxrDllLocation; STRU struExeLocation; try { - if (ppAspNetCoreConfig == NULL) + if (ppAspNetCoreConfig == nullptr) { hr = E_INVALIDARG; goto Finished; } - *ppAspNetCoreConfig = NULL; + *ppAspNetCoreConfig = nullptr; pRequestHandlerConfig = new REQUESTHANDLER_CONFIG; @@ -58,7 +58,7 @@ REQUESTHANDLER_CONFIG::CreateRequestHandlerConfig( } *ppAspNetCoreConfig = pRequestHandlerConfig; - pRequestHandlerConfig = NULL; + pRequestHandlerConfig = nullptr; } catch (std::bad_alloc&) { @@ -67,10 +67,10 @@ REQUESTHANDLER_CONFIG::CreateRequestHandlerConfig( Finished: - if (pRequestHandlerConfig != NULL) + if (pRequestHandlerConfig != nullptr) { delete pRequestHandlerConfig; - pRequestHandlerConfig = NULL; + pRequestHandlerConfig = nullptr; } return hr; @@ -89,19 +89,19 @@ REQUESTHANDLER_CONFIG::Populate( STRU strEnvValue; STRU strExpandedEnvValue; STRU strApplicationFullPath; - IAppHostAdminManager *pAdminManager = NULL; - IAppHostElement *pAspNetCoreElement = NULL; - IAppHostElement *pWindowsAuthenticationElement = NULL; - IAppHostElement *pBasicAuthenticationElement = NULL; - IAppHostElement *pAnonymousAuthenticationElement = NULL; + IAppHostAdminManager *pAdminManager = nullptr; + IAppHostElement *pAspNetCoreElement = nullptr; + IAppHostElement *pWindowsAuthenticationElement = nullptr; + IAppHostElement *pBasicAuthenticationElement = nullptr; + IAppHostElement *pAnonymousAuthenticationElement = nullptr; ULONGLONG ullRawTimeSpan = 0; DWORD dwCounter = 0; DWORD dwPosition = 0; - WCHAR* pszPath = NULL; - BSTR bstrWindowAuthSection = NULL; - BSTR bstrBasicAuthSection = NULL; - BSTR bstrAnonymousAuthSection = NULL; - BSTR bstrAspNetCoreSection = NULL; + WCHAR* pszPath = nullptr; + BSTR bstrWindowAuthSection = nullptr; + BSTR bstrBasicAuthSection = nullptr; + BSTR bstrAnonymousAuthSection = nullptr; + BSTR bstrAspNetCoreSection = nullptr; std::optional launcherPathEnv; std::optional launcherArgsEnv; @@ -161,7 +161,7 @@ REQUESTHANDLER_CONFIG::Populate( } bstrWindowAuthSection = SysAllocString(CS_WINDOWS_AUTHENTICATION_SECTION); - if (bstrWindowAuthSection == NULL) + if (bstrWindowAuthSection == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -188,7 +188,7 @@ REQUESTHANDLER_CONFIG::Populate( } bstrBasicAuthSection = SysAllocString(CS_BASIC_AUTHENTICATION_SECTION); - if (bstrBasicAuthSection == NULL) + if (bstrBasicAuthSection == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -213,7 +213,7 @@ REQUESTHANDLER_CONFIG::Populate( } bstrAnonymousAuthSection = SysAllocString(CS_ANONYMOUS_AUTHENTICATION_SECTION); - if (bstrAnonymousAuthSection == NULL) + if (bstrAnonymousAuthSection == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -238,7 +238,7 @@ REQUESTHANDLER_CONFIG::Populate( } bstrAspNetCoreSection = SysAllocString(CS_ASPNETCORE_SECTION); - if (bstrAspNetCoreSection == NULL) + if (bstrAspNetCoreSection == nullptr) { hr = E_OUTOFMEMORY; goto Finished; @@ -423,28 +423,28 @@ REQUESTHANDLER_CONFIG::Populate( Finished: - if (pAspNetCoreElement != NULL) + if (pAspNetCoreElement != nullptr) { pAspNetCoreElement->Release(); - pAspNetCoreElement = NULL; + pAspNetCoreElement = nullptr; } - if (pWindowsAuthenticationElement != NULL) + if (pWindowsAuthenticationElement != nullptr) { pWindowsAuthenticationElement->Release(); - pWindowsAuthenticationElement = NULL; + pWindowsAuthenticationElement = nullptr; } - if (pAnonymousAuthenticationElement != NULL) + if (pAnonymousAuthenticationElement != nullptr) { pAnonymousAuthenticationElement->Release(); - pAnonymousAuthenticationElement = NULL; + pAnonymousAuthenticationElement = nullptr; } - if (pBasicAuthenticationElement != NULL) + if (pBasicAuthenticationElement != nullptr) { pBasicAuthenticationElement->Release(); - pBasicAuthenticationElement = NULL; + pBasicAuthenticationElement = nullptr; } return hr; diff --git a/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.h b/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.h index fc5d01b109e0..23093f828034 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.h @@ -236,7 +236,7 @@ class REQUESTHANDLER_CONFIG REQUESTHANDLER_CONFIG() : m_fStdoutLogEnabled(FALSE), m_hostingModel(HOSTING_UNKNOWN), - m_ppStrArguments(NULL) + m_ppStrArguments(nullptr) { } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/gtest/gtest.vcxproj b/src/Servers/IIS/AspNetCoreModuleV2/gtest/gtest.vcxproj index bf7e421173d9..c02269e206d7 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/gtest/gtest.vcxproj +++ b/src/Servers/IIS/AspNetCoreModuleV2/gtest/gtest.vcxproj @@ -7,6 +7,7 @@ {CAC1267B-8778-4257-AAC6-CAF481723B01} gtest + false gtest diff --git a/src/Servers/IIS/Directory.Build.props b/src/Servers/IIS/Directory.Build.props index e167d783b593..624773c5b877 100644 --- a/src/Servers/IIS/Directory.Build.props +++ b/src/Servers/IIS/Directory.Build.props @@ -8,6 +8,6 @@ x64 $(NetCoreTargetingPackRoot)Microsoft.NETCore.App.Host.win-$(HostArch)\$(LibNetHostAppPackVersion)\runtimes\win-$(HostArch)\native - v142 + 143 diff --git a/src/Servers/IIS/build/Build.Common.Settings b/src/Servers/IIS/build/Build.Common.Settings index 196e069eafa4..cebc071c6d4c 100644 --- a/src/Servers/IIS/build/Build.Common.Settings +++ b/src/Servers/IIS/build/Build.Common.Settings @@ -32,6 +32,12 @@ + + ..\DefaultRules.ruleset + true + $(RunCodeAnalysis) + + Use From 0a6205528ce2e15c6f566fbb4a4fb956ff8ca00d Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Sat, 5 Oct 2024 23:25:47 -0700 Subject: [PATCH 2/8] Fix several C6xxx memory warnings in ANCM. --- .../AspNetCoreModuleV2/DefaultRules.ruleset | 12 +- .../IIS/AspNetCoreModuleV2/IISLib/base64.cpp | 269 +++--------------- .../IIS/AspNetCoreModuleV2/IISLib/base64.h | 16 -- .../IIS/AspNetCoreModuleV2/IISLib/buffer.h | 2 +- .../IIS/AspNetCoreModuleV2/IISLib/hashtable.h | 6 + .../IIS/AspNetCoreModuleV2/IISLib/stringa.cpp | 10 +- .../IIS/AspNetCoreModuleV2/IISLib/stringa.h | 3 + .../IIS/AspNetCoreModuleV2/IISLib/util.cpp | 3 + .../managedexports.cpp | 1 + .../forwardinghandler.cpp | 10 +- .../serverprocess.cpp | 3 +- .../winhttphelper.cpp | 4 + 12 files changed, 75 insertions(+), 264 deletions(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset index 147ad0a5677e..42d299c4f25e 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset +++ b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset @@ -291,8 +291,8 @@ - - + + @@ -303,7 +303,7 @@ - + @@ -347,7 +347,7 @@ - + @@ -396,8 +396,8 @@ - - + + diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.cpp b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.cpp index b5c910b9b573..cc4ce3f75cbe 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.cpp @@ -56,6 +56,12 @@ Return Values: if (cchEncodedStringSize == 0 && pszEncodedString == nullptr) { return ERROR_SUCCESS; } + else if (pszEncodedString == nullptr) + { + return ERROR_INVALID_PARAMETER; + } + + *pszEncodedString = 0; if (cchEncodedStringSize < cchEncoded) { // Given buffer is too small to hold encoded string. @@ -66,8 +72,16 @@ Return Values: ib = ich = 0; while (ib < cbDecodedBufferSize) { b0 = pbDecodedBuffer[ib++]; - b1 = (ib < cbDecodedBufferSize) ? pbDecodedBuffer[ib++] : 0; - b2 = (ib < cbDecodedBufferSize) ? pbDecodedBuffer[ib++] : 0; + b1 = 0; + b2 = 0; + if (ib < cbDecodedBufferSize) + { + b1 = pbDecodedBuffer[ib++]; + } + if (ib < cbDecodedBufferSize) + { + b2 = pbDecodedBuffer[ib++]; + } // // The checks below for buffer overflow seems redundant to me. @@ -126,122 +140,6 @@ Return Values: } -DWORD -Base64Decode( - __in PCWSTR pszEncodedString, - __out_opt VOID * pDecodeBuffer, - __in DWORD cbDecodeBufferSize, - __out_opt DWORD * pcbDecoded - ) -/*++ - -Routine Description: - - Decode a base64-encoded string. - -Arguments: - - pszEncodedString (IN) - base64-encoded string to decode. - cbDecodeBufferSize (IN) - size in bytes of the decode buffer. - pbDecodeBuffer (OUT) - holds the decoded data. - pcbDecoded (OUT) - number of data bytes in the decoded data (if success or - STATUS_BUFFER_TOO_SMALL). - -Return Values: - - 0 - success. - E_OUTOFMEMORY - E_INVALIDARG - ---*/ -{ -constexpr auto NA = (255); -#define DECODE(x) (((ULONG)(x) < sizeof(rgbDecodeTable)) ? rgbDecodeTable[x] : NA) - - static BYTE rgbDecodeTable[128] = { - NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, // 0-15 - NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, // 16-31 - NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 62, NA, NA, NA, 63, // 32-47 - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NA, NA, NA, 0, NA, NA, // 48-63 - NA, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 64-79 - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NA, NA, NA, NA, NA, // 80-95 - NA, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 96-111 - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, NA, NA, NA, NA, NA, // 112-127 - }; - - DWORD cbDecoded; - DWORD cchEncodedSize; - DWORD ich; - DWORD ib; - BYTE b0, b1, b2, b3; - BYTE * pbDecodeBuffer = (BYTE *) pDecodeBuffer; - - cchEncodedSize = (DWORD)wcslen(pszEncodedString); - if (nullptr != pcbDecoded) { - *pcbDecoded = 0; - } - - if ((0 == cchEncodedSize) || (0 != (cchEncodedSize % 4))) { - // Input string is not sized correctly to be base64. - return ERROR_INVALID_PARAMETER; - } - - // Calculate decoded buffer size. - cbDecoded = (cchEncodedSize + 3) / 4 * 3; - if (pszEncodedString[cchEncodedSize-1] == '=') { - if (pszEncodedString[cchEncodedSize-2] == '=') { - // Only one data byte is encoded in the last cluster. - cbDecoded -= 2; - } - else { - // Only two data bytes are encoded in the last cluster. - cbDecoded -= 1; - } - } - - if (nullptr != pcbDecoded) { - *pcbDecoded = cbDecoded; - } - - if (cbDecodeBufferSize == 0 && pDecodeBuffer == nullptr) { - return ERROR_SUCCESS; - } - - if (cbDecoded > cbDecodeBufferSize) { - // Supplied buffer is too small. - return ERROR_INSUFFICIENT_BUFFER; - } - - // Decode each four-byte cluster into the corresponding three data bytes. - ich = ib = 0; - while (ich < cchEncodedSize) { - b0 = DECODE(pszEncodedString[ich]); ich++; - b1 = DECODE(pszEncodedString[ich]); ich++; - b2 = DECODE(pszEncodedString[ich]); ich++; - b3 = DECODE(pszEncodedString[ich]); ich++; - - if ((NA == b0) || (NA == b1) || (NA == b2) || (NA == b3)) { - // Contents of input string are not base64. - return ERROR_INVALID_PARAMETER; - } - - pbDecodeBuffer[ib++] = (b0 << 2) | (b1 >> 4); - - if (ib < cbDecoded) { - pbDecodeBuffer[ib++] = (b1 << 4) | (b2 >> 2); - - if (ib < cbDecoded) { - pbDecodeBuffer[ib++] = (b2 << 6) | b3; - } - } - } - - DBG_ASSERT(ib == cbDecoded); - - return ERROR_SUCCESS; -} - - DWORD Base64Encode( __in_bcount(cbDecodedBufferSize) VOID * pDecodedBuffer, @@ -295,6 +193,12 @@ Return Values: if (cchEncodedStringSize == 0 && pszEncodedString == nullptr) { return ERROR_SUCCESS; } + else if (pszEncodedString == nullptr) + { + return ERROR_INVALID_PARAMETER; + } + + *pszEncodedString = 0; if (cchEncodedStringSize < cchEncoded) { // Given buffer is too small to hold encoded string. @@ -305,8 +209,16 @@ Return Values: ib = ich = 0; while (ib < cbDecodedBufferSize) { b0 = pbDecodedBuffer[ib++]; - b1 = (ib < cbDecodedBufferSize) ? pbDecodedBuffer[ib++] : 0; - b2 = (ib < cbDecodedBufferSize) ? pbDecodedBuffer[ib++] : 0; + b1 = 0; + b2 = 0; + if (ib < cbDecodedBufferSize) + { + b1 = pbDecodedBuffer[ib++]; + } + if (ib < cbDecodedBufferSize) + { + b2 = pbDecodedBuffer[ib++]; + } // // The checks below for buffer overflow seems redundant to me. @@ -363,120 +275,3 @@ Return Values: return ERROR_SUCCESS; } - - -DWORD -Base64Decode( - __in PCSTR pszEncodedString, - __out_opt VOID * pDecodeBuffer, - __in DWORD cbDecodeBufferSize, - __out_opt DWORD * pcbDecoded - ) -/*++ - -Routine Description: - - Decode a base64-encoded string. - -Arguments: - - pszEncodedString (IN) - base64-encoded string to decode. - cbDecodeBufferSize (IN) - size in bytes of the decode buffer. - pbDecodeBuffer (OUT) - holds the decoded data. - pcbDecoded (OUT) - number of data bytes in the decoded data (if success or - STATUS_BUFFER_TOO_SMALL). - -Return Values: - - 0 - success. - E_OUTOFMEMORY - E_INVALIDARG - ---*/ -{ -#define NA (255) -#define DECODE(x) (((ULONG)(x) < sizeof(rgbDecodeTable)) ? rgbDecodeTable[x] : NA) - - static BYTE rgbDecodeTable[128] = { - NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, // 0-15 - NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, // 16-31 - NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 62, NA, NA, NA, 63, // 32-47 - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NA, NA, NA, 0, NA, NA, // 48-63 - NA, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 64-79 - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NA, NA, NA, NA, NA, // 80-95 - NA, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 96-111 - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, NA, NA, NA, NA, NA, // 112-127 - }; - - DWORD cbDecoded; - DWORD cchEncodedSize; - DWORD ich; - DWORD ib; - BYTE b0, b1, b2, b3; - BYTE * pbDecodeBuffer = (BYTE *) pDecodeBuffer; - - cchEncodedSize = (DWORD)strlen(pszEncodedString); - if (nullptr != pcbDecoded) { - *pcbDecoded = 0; - } - - if ((0 == cchEncodedSize) || (0 != (cchEncodedSize % 4))) { - // Input string is not sized correctly to be base64. - return ERROR_INVALID_PARAMETER; - } - - // Calculate decoded buffer size. - cbDecoded = (cchEncodedSize + 3) / 4 * 3; - if (pszEncodedString[cchEncodedSize-1] == '=') { - if (pszEncodedString[cchEncodedSize-2] == '=') { - // Only one data byte is encoded in the last cluster. - cbDecoded -= 2; - } - else { - // Only two data bytes are encoded in the last cluster. - cbDecoded -= 1; - } - } - - if (nullptr != pcbDecoded) { - *pcbDecoded = cbDecoded; - } - - if (cbDecodeBufferSize == 0 && pDecodeBuffer == nullptr) { - return ERROR_SUCCESS; - } - - if (cbDecoded > cbDecodeBufferSize) { - // Supplied buffer is too small. - return ERROR_INSUFFICIENT_BUFFER; - } - - // Decode each four-byte cluster into the corresponding three data bytes. - ich = ib = 0; - while (ich < cchEncodedSize) { - b0 = DECODE(pszEncodedString[ich]); ich++; - b1 = DECODE(pszEncodedString[ich]); ich++; - b2 = DECODE(pszEncodedString[ich]); ich++; - b3 = DECODE(pszEncodedString[ich]); ich++; - - if ((NA == b0) || (NA == b1) || (NA == b2) || (NA == b3)) { - // Contents of input string are not base64. - return ERROR_INVALID_PARAMETER; - } - - pbDecodeBuffer[ib++] = (b0 << 2) | (b1 >> 4); - - if (ib < cbDecoded) { - pbDecodeBuffer[ib++] = (b1 << 4) | (b2 >> 2); - - if (ib < cbDecoded) { - pbDecodeBuffer[ib++] = (b2 << 6) | b3; - } - } - } - - DBG_ASSERT(ib == cbDecoded); - - return ERROR_SUCCESS; -} - diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.h b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.h index 885abdc6e3b2..265116d1cf52 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/base64.h @@ -15,14 +15,6 @@ Base64Encode( __out_opt DWORD * pcchEncoded ); -DWORD -Base64Decode( - __in PCWSTR pszEncodedString, - __out_opt VOID * pDecodeBuffer, - __in DWORD cbDecodeBufferSize, - __out_opt DWORD * pcbDecoded - ); - DWORD Base64Encode( __in_bcount( cbDecodedBufferSize ) VOID * pDecodedBuffer, @@ -32,13 +24,5 @@ Base64Encode( __out_opt DWORD * pcchEncoded ); -DWORD -Base64Decode( - __in PCSTR pszEncodedString, - __out_opt VOID * pDecodeBuffer, - __in DWORD cbDecodeBufferSize, - __out_opt DWORD * pcbDecoded - ); - #endif // _BASE64_HXX_ diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/buffer.h b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/buffer.h index 385b73d717e3..339f307fb60a 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/buffer.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/buffer.h @@ -259,7 +259,7 @@ C_ASSERT( sizeof(VOID*) <= sizeof(ULONGLONG) ); // bytes. If the buffer overflows then a heap buffer will be allocated. // #define STACK_BUFFER( _name, _size ) \ - ULONGLONG __aqw##_name[ ( ( (_size) + sizeof(ULONGLONG) - 1 ) / sizeof(ULONGLONG) ) ]; \ + ULONGLONG __aqw##_name[ ( ( (_size) + sizeof(ULONGLONG) - 1 ) / sizeof(ULONGLONG) ) ]{}; \ BUFFER _name( (BYTE*)__aqw##_name, sizeof(__aqw##_name) ) // diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashtable.h b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashtable.h index 6f0bb9de3610..c16e1cb32a87 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashtable.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashtable.h @@ -389,6 +389,9 @@ HASH_TABLE<_Record,_Key>::FindKey( _tableLock.SharedAcquire(); + // Dereferencing NULL pointer 'pNode' + // FindNodeInternal will set a non-null pNode when true is returned, just need to figure out how to correctly SAL the method +#pragma warning(suppress: 6011) if (FindNodeInternal(key, dwHash, &pNode) && pNode->_pRecord != nullptr) { @@ -507,6 +510,9 @@ HASH_TABLE<_Record,_Key>::DeleteKey( if (FindNodeInternal(key, dwHash, &pNode, &ppPreviousNodeNextPointer)) { + // Dereferencing NULL pointer 'pNode' + // FindNodeInternal will set a non-null pNode when true is returned, just need to figure out how to correctly SAL the method +#pragma warning(suppress: 6011) *ppPreviousNodeNextPointer = pNode->_pNext; DeleteNode(pNode); _nItems--; diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp index b8ee1b11962f..d317461b792a 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp @@ -135,6 +135,12 @@ STRA::QueryStr( return m_Buff.QueryPtr(); } +VOID STRA::EnsureNullTerminated() +{ + // m_cchLen represents the string's length, not the underlying buffer length + m_Buff.QueryPtr()[m_cchLen] = '\0'; +} + VOID STRA::Reset( ) @@ -696,7 +702,7 @@ Return Value: _ASSERTE( pch ); - while (pch[i] != NULL) + while ((DWORD)i < m_cchLen && pch[i] != NULL) { // // Escape characters that are in the non-printable range @@ -1154,7 +1160,7 @@ STRA::AuxAppendW( // ensure we're still NULL terminated in the right spot // (regardless of success or failure) // - QueryStr()[m_cchLen] = '\0'; + EnsureNullTerminated(); return hr; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.h b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.h index 0d1f50d50c93..f58971b48444 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.h @@ -143,6 +143,9 @@ class STRA QueryStr( ) const; + + VOID EnsureNullTerminated(); + VOID Reset( ); diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/util.cpp b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/util.cpp index 214ee65abfe4..37689befec92 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/util.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/util.cpp @@ -47,6 +47,9 @@ Return Values: // we need to change it to Win32 from ("\\?\") // + // Buffer overrun while writing to 'pstrPath->QueryStr()' + // We know it's not an overrun because we just copied pszName into pstrPath and pszName is at least 4 in length +#pragma warning(suppress: 6386) pstrPath->QueryStr()[2] = L'?'; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp index eea153ca6954..2955ea728fff 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp @@ -278,6 +278,7 @@ http_read_request_bytes( ) { HRESULT hr = S_OK; + *pvBuffer = 0; if (pInProcessHandler == nullptr) { diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp index 2ebc0c6ddbf8..f53ce0e4f5a2 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp @@ -1498,6 +1498,8 @@ FORWARDING_HANDLER::OnWinHttpCompletionSendRequestOrWriteComplete( HRESULT hr = S_OK; IHttpRequest * pRequest = m_pW3Context->GetRequest(); + *pfClientError = FALSE; + // // completion for sending the initial request or request entity to // winhttp, get more request entity if available, else start receiving @@ -1599,7 +1601,7 @@ FORWARDING_HANDLER::OnWinHttpCompletionStatusHeadersAvailable( STACK_STRA(strHeaders, 2048); DWORD dwHeaderSize = bufHeaderBuffer.QuerySize(); - UNREFERENCED_PARAMETER(pfAnotherCompletionExpected); + *pfAnotherCompletionExpected = FALSE; // // Headers are available, read the status line and headers and pass @@ -1697,6 +1699,8 @@ FORWARDING_HANDLER::OnWinHttpCompletionStatusDataAvailable( { HRESULT hr = S_OK; + *pfAnotherCompletionExpected = FALSE; + // // Response data is available from winhttp, read it // @@ -1750,6 +1754,8 @@ FORWARDING_HANDLER::OnWinHttpCompletionStatusReadComplete( { HRESULT hr = S_OK; + *pfAnotherCompletionExpected = FALSE; + // // Response data has been read from winhttp, send it to the client // @@ -1826,6 +1832,8 @@ FORWARDING_HANDLER::OnSendingRequest( __out BOOL * pfClientError ) { + *pfClientError = FALSE; + // // This is a completion for a read from http.sys, abort in case // of failure, if we read anything write it out over WinHTTP, diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/serverprocess.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/serverprocess.cpp index e1aaae6493a0..cc72e1cf6b63 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/serverprocess.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/serverprocess.cpp @@ -471,7 +471,7 @@ SERVER_PROCESS::SetupCommandLine( Finished: if (pszFullPath != nullptr) { - delete pszFullPath; + delete[] pszFullPath; } return hr; } @@ -963,6 +963,7 @@ SERVER_PROCESS::SetWindowsAuthToken( ) { HRESULT hr = S_OK; + *pTargetTokenHandle = nullptr; if (m_hListeningProcessHandle != nullptr && m_hListeningProcessHandle != INVALID_HANDLE_VALUE) { diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.cpp index 1d0bbe742350..76c848673f43 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.cpp @@ -69,6 +69,10 @@ WINHTTP_HELPER::GetFlagsFromBufferType( __out BOOL * pfClose ) { + *pfClose = FALSE; + *pfFinalFragment = FALSE; + *pfUtf8Encoded = FALSE; + switch (BufferType) { case WINHTTP_WEB_SOCKET_BINARY_MESSAGE_BUFFER_TYPE: From 321c2aaa7922c329eed3b92dae27cb439a69067e Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Tue, 8 Oct 2024 13:14:30 -0700 Subject: [PATCH 3/8] Enable CA for CommonLib and address additional errors. --- .../CommonLib/CommonLib.vcxproj | 3 +-- .../CommonLib/Environment.cpp | 2 +- .../AspNetCoreModuleV2/CommonLib/EventLog.cpp | 4 ++-- .../CommonLib/GlobalVersionUtility.cpp | 10 ++++----- .../CommonLib/HostFxrResolver.cpp | 22 +++++++++---------- .../CommonLib/RegistryKey.cpp | 2 +- .../CommonLib/StringHelpers.cpp | 2 +- .../CommonLib/debugutil.cpp | 14 ++++++++---- .../CommonLib/file_utility.cpp | 8 +++---- 9 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj index 1525039d18a9..4e8a906e079f 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj @@ -1,11 +1,10 @@ - {55494E58-E061-4C4C-A0A8-837008E72F85} NewCommon - false + ..\iislib;$(LibNetHostPath) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/Environment.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/Environment.cpp index c49200ce8d2f..8112de09b6e6 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/Environment.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/Environment.cpp @@ -168,7 +168,7 @@ void Environment::CopyToDirectoryInner(const std::filesystem::path& source, cons auto destinationDirEntry = std::filesystem::directory_entry(destination); if (!destinationDirEntry.exists()) { - CreateDirectory(destination.wstring().c_str(), NULL); + CreateDirectory(destination.wstring().c_str(), nullptr); } for (auto& path : std::filesystem::directory_iterator(source)) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/EventLog.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/EventLog.cpp index fb66d9d65c74..3ec4cc4a3447 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/EventLog.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/EventLog.cpp @@ -36,11 +36,11 @@ EventLog::LogEventNoTrace( dwEventInfoType, 0, // wCategory dwEventId, - NULL, // lpUserSid + nullptr, // lpUserSid static_cast(eventLogDataStrings.size()), // wNumStrings 0, // dwDataSize, eventLogDataStrings.data(), - NULL // lpRawData + nullptr // lpRawData ); } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/GlobalVersionUtility.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/GlobalVersionUtility.cpp index b02fcfc44592..a7989862868c 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/GlobalVersionUtility.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/GlobalVersionUtility.cpp @@ -13,17 +13,17 @@ namespace fs = std::filesystem; std::wstring GlobalVersionUtility::GetGlobalRequestHandlerPath(PCWSTR pwzAspNetCoreFolderPath, PCWSTR pwzHandlerVersion, PCWSTR pwzHandlerName) { - if (pwzAspNetCoreFolderPath == NULL) + if (pwzAspNetCoreFolderPath == nullptr) { throw new std::invalid_argument("pwzAspNetCoreFolderPath is NULL"); } - if (pwzHandlerVersion == NULL) + if (pwzHandlerVersion == nullptr) { throw new std::invalid_argument("pwzHandlerVersion is NULL"); } - if (pwzHandlerName == NULL) + if (pwzHandlerName == nullptr) { throw new std::invalid_argument("pwzHandlerName is NULL"); } @@ -47,7 +47,7 @@ GlobalVersionUtility::GetGlobalRequestHandlerPath(PCWSTR pwzAspNetCoreFolderPath std::vector GlobalVersionUtility::GetRequestHandlerVersions(PCWSTR pwzAspNetCoreFolderPath) { - if (pwzAspNetCoreFolderPath == NULL) + if (pwzAspNetCoreFolderPath == nullptr) { throw new std::invalid_argument("pwzAspNetCoreFolderPath is NULL"); } @@ -74,7 +74,7 @@ GlobalVersionUtility::GetRequestHandlerVersions(PCWSTR pwzAspNetCoreFolderPath) std::wstring GlobalVersionUtility::FindHighestGlobalVersion(PCWSTR pwzAspNetCoreFolderPath) { - if (pwzAspNetCoreFolderPath == NULL) + if (pwzAspNetCoreFolderPath == nullptr) { throw std::invalid_argument("pwzAspNetCoreFolderPath is NULL"); } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp index 9b12cd0132b4..3ba914135958 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp @@ -400,8 +400,8 @@ HostFxrResolver::InvokeWhereToFindDotnet() { HRESULT hr = S_OK; // Arguments to call where.exe - STARTUPINFOW startupInfo = { 0 }; - PROCESS_INFORMATION processInformation = { 0 }; + STARTUPINFOW startupInfo{}; + PROCESS_INFORMATION processInformation{}; SECURITY_ATTRIBUTES securityAttributes; CHAR pzFileContents[READ_BUFFER_SIZE]; @@ -409,7 +409,7 @@ HostFxrResolver::InvokeWhereToFindDotnet() HandleWrapper hStdOutWritePipe; HandleWrapper hProcess; HandleWrapper hThread; - CComBSTR pwzDotnetName = NULL; + CComBSTR pwzDotnetName = nullptr; DWORD dwFilePointer; BOOL fIsCurrentProcess64Bit; DWORD dwExitCode; @@ -423,7 +423,7 @@ HostFxrResolver::InvokeWhereToFindDotnet() // Set the security attributes for the read/write pipe securityAttributes.nLength = sizeof(securityAttributes); - securityAttributes.lpSecurityDescriptor = NULL; + securityAttributes.lpSecurityDescriptor = nullptr; securityAttributes.bInheritHandle = TRUE; LOG_INFO(L"Invoking where.exe to find dotnet.exe"); @@ -443,14 +443,14 @@ HostFxrResolver::InvokeWhereToFindDotnet() pwzDotnetName = L"\"where.exe\" dotnet.exe"; // Create a process to invoke where.exe - FINISHED_LAST_ERROR_IF(!CreateProcessW(NULL, + FINISHED_LAST_ERROR_IF(!CreateProcessW(nullptr, pwzDotnetName, - NULL, - NULL, + nullptr, + nullptr, TRUE, CREATE_NO_WINDOW, - NULL, - NULL, + nullptr, + nullptr, &startupInfo, &processInformation )); @@ -480,7 +480,7 @@ HostFxrResolver::InvokeWhereToFindDotnet() // Where succeeded. // Reset file pointer to the beginning of the file. - dwFilePointer = SetFilePointer(hStdOutReadPipe, 0, NULL, FILE_BEGIN); + dwFilePointer = SetFilePointer(hStdOutReadPipe, 0, nullptr, FILE_BEGIN); if (dwFilePointer == INVALID_SET_FILE_POINTER) { FINISHED_IF_FAILED(E_FAIL); @@ -490,7 +490,7 @@ HostFxrResolver::InvokeWhereToFindDotnet() // As the call to where.exe succeeded (dotnet.exe was found), ReadFile should not hang. // TODO consider putting ReadFile in a separate thread with a timeout to guarantee it doesn't block. // - FINISHED_LAST_ERROR_IF (!ReadFile(hStdOutReadPipe, pzFileContents, READ_BUFFER_SIZE, &dwNumBytesRead, NULL)); + FINISHED_LAST_ERROR_IF (!ReadFile(hStdOutReadPipe, pzFileContents, READ_BUFFER_SIZE, &dwNumBytesRead, nullptr)); if (dwNumBytesRead >= READ_BUFFER_SIZE) { diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.cpp index 63828821f93c..475edbe6b90f 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RegistryKey.cpp @@ -18,7 +18,7 @@ std::optional RegistryKey::TryGetDWORD(HKEY section, const std::wstring& std::optional RegistryKey::TryGetString(HKEY section, const std::wstring& subSectionName, const std::wstring& valueName) { - DWORD cbData; + DWORD cbData{}; if (!CheckReturnValue(RegGetValue(section, subSectionName.c_str(), valueName.c_str(), RRF_RT_REG_SZ, nullptr, nullptr, &cbData))) { diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/StringHelpers.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/StringHelpers.cpp index 4fb06330950b..bc81d5d00ecc 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/StringHelpers.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/StringHelpers.cpp @@ -41,7 +41,7 @@ std::wstring to_wide_string(const std::string& source, const int length, const u std::wstring destination; - int nChars = MultiByteToWideChar(codePage, 0, source.data(), length, NULL, 0); + int nChars = MultiByteToWideChar(codePage, 0, source.data(), length, nullptr, 0); THROW_LAST_ERROR_IF(nChars == 0); destination.resize(nChars); diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp index 513c571cdbed..7b28390fdbeb 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp @@ -73,7 +73,7 @@ GetVersionInfoString() { DWORD verHandle = 0; UINT size = 0; - LPVOID lpBuffer = NULL; + LPVOID lpBuffer = nullptr; auto path = GetModuleName(); @@ -92,7 +92,7 @@ GetVersionInfoString() RETURN_IF_FAILED(E_FAIL); } - LPVOID pvProductName = NULL; + LPVOID pvProductName = nullptr; unsigned int iProductNameLen = 0; RETURN_LAST_ERROR_IF(!VerQueryValue(verData.data(), _T("\\StringFileInfo\\040904b0\\FileDescription"), &pvProductName, &iProductNameLen)); @@ -114,7 +114,7 @@ std::wstring GetModuleName() { WCHAR path[MAX_PATH]; - LOG_LAST_ERROR_IF(!GetModuleFileName(g_hModule, path, sizeof(path))); + LOG_LAST_ERROR_IF(!GetModuleFileName(g_hModule, path, MAX_PATH)); return path; } @@ -218,7 +218,7 @@ DebugInitialize(HMODULE hModule) cbData = sizeof(dwData); if ((RegQueryValueEx(hKey, L"DebugFlags", - NULL, + nullptr, &dwType, (LPBYTE)&dwData, &cbData) == NO_ERROR) && @@ -409,7 +409,10 @@ DebugPrintfW( hr = strCooked.SafeVsnwprintf(szFormat, args ); +#pragma warning(push) +#pragma warning(disable: 26477) // va_end uses 0 va_end( args ); +#pragma warning(pop) if (FAILED (hr)) { @@ -453,7 +456,10 @@ DebugPrintf( hr = strCooked.SafeVsnprintf(szFormat, args ); +#pragma warning(push) +#pragma warning(disable: 26477) // va_end uses 0 va_end( args ); +#pragma warning(pop) if (FAILED (hr)) { diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/file_utility.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/file_utility.cpp index c7d3b47deda5..2c67d968cbd5 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/file_utility.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/file_utility.cpp @@ -41,7 +41,7 @@ FILE_UTILITY::ConvertPathToFullPath( { HRESULT hr = S_OK; STRU strFileFullPath; - LPWSTR pszFullPath = NULL; + LPWSTR pszFullPath = nullptr; // if relative path, prefix with root path and then convert to absolute path. if ( PathIsRelative(pszPath) ) @@ -72,7 +72,7 @@ FILE_UTILITY::ConvertPathToFullPath( if(_wfullpath( pszFullPath, strFileFullPath.QueryStr(), - strFileFullPath.QueryCCH() + 1 ) == NULL ) + strFileFullPath.QueryCCH() + 1 ) == nullptr ) { hr = HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER ); goto Finished; @@ -87,10 +87,10 @@ FILE_UTILITY::ConvertPathToFullPath( Finished: - if ( pszFullPath != NULL ) + if ( pszFullPath != nullptr ) { delete[] pszFullPath; - pszFullPath = NULL; + pszFullPath = nullptr; } return hr; From 09595895c3c2f5316ba4bab07b7507b18cf8949e Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Tue, 8 Oct 2024 13:22:26 -0700 Subject: [PATCH 4/8] Fix C26474 (use implicit conversion). --- src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset | 2 +- .../OutOfProcessRequestHandler/forwardinghandler.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset index 42d299c4f25e..3a13dfc87744 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset +++ b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset @@ -76,7 +76,7 @@ - + diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp index f53ce0e4f5a2..ab22cd4755be 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp @@ -262,7 +262,7 @@ FORWARDING_HANDLER::ExecuteRequestHandler() nullptr, 0, cbContentLength, - reinterpret_cast(static_cast(this)))) + reinterpret_cast(this))) { hr = HRESULT_FROM_WIN32(GetLastError()); From d35b77073a1c46815bf4e1b36ff063d852673145 Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Tue, 8 Oct 2024 13:27:16 -0700 Subject: [PATCH 5/8] Fix unnanotated fallthroughs - C26819 --- src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/dllmain.cpp | 1 + src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset | 2 +- .../IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp | 1 + .../AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/dllmain.cpp b/src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/dllmain.cpp index 4d55e36b80d9..050e6b301b4e 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/dllmain.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/dllmain.cpp @@ -57,6 +57,7 @@ BOOL WINAPI DllMain(HMODULE hModule, // this is a bug in IIS. To try to avoid AVs, we will set a global flag g_fInShutdown = TRUE; StaticCleanup(); + break; default: break; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset index 3a13dfc87744..64f8574d9864 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset +++ b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset @@ -99,7 +99,7 @@ - + diff --git a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp index 509dc3f3e848..cc2d5e3c45bf 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp @@ -85,6 +85,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, IN_PROCESS_HANDLER::StaticTerminate(); ALLOC_CACHE_HANDLER::StaticTerminate(); DebugStop(); + break; default: break; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp index 449ec6a2877a..51e1584fd8f1 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp @@ -223,6 +223,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, FORWARDING_HANDLER::StaticTerminate(); ALLOC_CACHE_HANDLER::StaticTerminate(); DebugStop(); + break; default: break; } From d0e7f8cdd7df49dc2159bd1325ed44d7af2652a5 Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Tue, 8 Oct 2024 13:38:15 -0700 Subject: [PATCH 6/8] Fix SAL related CA warnings. --- src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset | 3 +-- .../OutOfProcessRequestHandler/winhttphelper.h | 2 +- .../IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset index 64f8574d9864..50e2691ee2e8 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset +++ b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset @@ -248,7 +248,7 @@ - + @@ -427,7 +427,6 @@ - diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.h b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.h index d583f6fb1032..230e8f8a3a95 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.h @@ -7,7 +7,7 @@ typedef HINTERNET (WINAPI * PFN_WINHTTP_WEBSOCKET_COMPLETE_UPGRADE)( _In_ HINTERNET hRequest, - _In_opt_ DWORD_PTR pContext + DWORD_PTR pContext ); diff --git a/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.h b/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.h index c73a76849703..3c4c01bc80ca 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.h @@ -50,7 +50,7 @@ class FILE_WATCHER{ static DWORD WINAPI CopyAndShutdown(FILE_WATCHER* watcher); - HRESULT HandleChangeCompletion(DWORD cbCompletion); + HRESULT HandleChangeCompletion(_In_ DWORD bytesTransferred); HRESULT Monitor(); void StopMonitor(); From 7aa9be1ea6c336e87b99f1aaf27586a818c9c066 Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Tue, 8 Oct 2024 13:57:53 -0700 Subject: [PATCH 7/8] Fix constexpr warnings and constant std::move warnings C26478 C26497. --- .../CommonLib/ServerErrorHandler.h | 2 +- .../AspNetCoreModuleV2/DefaultRules.ruleset | 3 +- .../IIS/AspNetCoreModuleV2/IISLib/hashfn.h | 36 +++++++++---------- .../StartupExceptionApplication.h | 2 +- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/ServerErrorHandler.h b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/ServerErrorHandler.h index 77d94230b256..ee99b743f7e5 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/ServerErrorHandler.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/ServerErrorHandler.h @@ -15,7 +15,7 @@ class ServerErrorHandler : public REQUEST_HANDLER m_disableStartupPage(disableStartupPage), m_statusCode(statusCode), m_subStatusCode(subStatusCode), - m_statusText(std::move(statusText)), + m_statusText(statusText), m_ExceptionInfoContent(responseContent) { } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset index 50e2691ee2e8..cef99f245b30 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset +++ b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset @@ -80,7 +80,6 @@ - @@ -95,7 +94,7 @@ - + diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashfn.h b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashfn.h index a7bfeda2cfad..881fd8eb4abf 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashfn.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashfn.h @@ -12,7 +12,7 @@ // the low end of the hashtable otherwise. LKRhash applies this internally // to all hash signatures for exactly this reason. -inline DWORD +inline constexpr DWORD HashScramble(DWORD dwHash) { // Here are 10 primes slightly greater than 10^9 @@ -20,9 +20,9 @@ HashScramble(DWORD dwHash) // 1000000093, 1000000097, 1000000103, 1000000123, 1000000181. // default value for "scrambling constant" - const DWORD RANDOM_CONSTANT = 314159269UL; + constexpr DWORD RANDOM_CONSTANT = 314159269UL; // large prime number, also used for scrambling - const DWORD RANDOM_PRIME = 1000000007UL; + constexpr DWORD RANDOM_PRIME = 1000000007UL; return (RANDOM_CONSTANT * dwHash) % RANDOM_PRIME ; } @@ -30,7 +30,7 @@ HashScramble(DWORD dwHash) // Faster scrambling function suggested by Eric Jacobsen -inline DWORD +inline DWORD constexpr HashRandomizeBits(DWORD dw) { return (((dw * 1103515245 + 12345) >> 16) @@ -39,7 +39,7 @@ HashRandomizeBits(DWORD dw) // Small prime number used as a multiplier in the supplied hash functions -const DWORD HASH_MULTIPLIER = 101; +constexpr DWORD HASH_MULTIPLIER = 101; #undef HASH_SHIFT_MULTIPLY @@ -273,51 +273,51 @@ Hash( } // Identity hash functions: scalar values map to themselves -inline DWORD Hash(char c) +inline constexpr DWORD Hash(char c) { return c; } -inline DWORD Hash(unsigned char uc) +inline constexpr DWORD Hash(unsigned char uc) { return uc; } -inline DWORD Hash(signed char sc) +inline constexpr DWORD Hash(signed char sc) { return sc; } -inline DWORD Hash(short sh) +inline constexpr DWORD Hash(short sh) { return sh; } -inline DWORD Hash(unsigned short ush) +inline constexpr DWORD Hash(unsigned short ush) { return ush; } -inline DWORD Hash(int i) +inline constexpr DWORD Hash(int i) { return i; } -inline DWORD Hash(unsigned int u) +inline constexpr DWORD Hash(unsigned int u) { return u; } -inline DWORD Hash(long l) +inline constexpr DWORD Hash(long l) { return l; } -inline DWORD Hash(unsigned long ul) +inline constexpr DWORD Hash(unsigned long ul) { return ul; } -inline DWORD Hash(float f) +inline constexpr DWORD Hash(float f) { // be careful of rounding errors when computing keys union { float f; DWORD dw; - } u; + } u{}; u.f = f; return u.dw; } -inline DWORD Hash(double dbl) +inline constexpr DWORD Hash(double dbl) { // be careful of rounding errors when computing keys union { double dbl; DWORD dw[2]; - } u; + } u{}; u.dbl = dbl; return u.dw[0] * HASH_MULTIPLIER + u.dw[1]; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/StartupExceptionApplication.h b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/StartupExceptionApplication.h index d3e50e620fa8..2793c7c404f2 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/StartupExceptionApplication.h +++ b/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/StartupExceptionApplication.h @@ -24,7 +24,7 @@ class StartupExceptionApplication : public InProcessApplicationBase m_error(errorPageContent), m_statusCode(statusCode), m_subStatusCode(subStatusCode), - m_statusText(std::move(statusText)), + m_statusText(statusText), InProcessApplicationBase(pServer, pApplication) { } From c1752f6b248b1953932d0249662588cafb30fe4c Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Wed, 9 Oct 2024 13:53:23 -0700 Subject: [PATCH 8/8] Minor improvements. --- src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp | 2 +- src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset | 1 + src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp | 2 +- .../OutOfProcessRequestHandler/winhttphelper.cpp | 4 +--- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp index 7b28390fdbeb..c203ad3ce1bf 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/debugutil.cpp @@ -114,7 +114,7 @@ std::wstring GetModuleName() { WCHAR path[MAX_PATH]; - LOG_LAST_ERROR_IF(!GetModuleFileName(g_hModule, path, MAX_PATH)); + LOG_LAST_ERROR_IF(!GetModuleFileName(g_hModule, path, _countof(path))); return path; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset index cef99f245b30..b9ae65054182 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset +++ b/src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset @@ -80,6 +80,7 @@ + diff --git a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp index d317461b792a..2aebe86cda87 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/IISLib/stringa.cpp @@ -470,7 +470,7 @@ Return Value: HRESULT hr = SafeVsnprintf(pszFormatString, argsList); -#pragma warning(suppress: 26477) +#pragma warning(suppress: 26477) // va_end uses 0 va_end( argsList ); return hr; } diff --git a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.cpp b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.cpp index 76c848673f43..1383fdbc45e6 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/winhttphelper.cpp @@ -21,9 +21,7 @@ WINHTTP_HELPER::sm_pfnWinHttpWebSocketQueryCloseStatus; //static HRESULT -WINHTTP_HELPER::StaticInitialize( - VOID -) +WINHTTP_HELPER::StaticInitialize() { // // Initialize the function pointers for WinHttp Websocket API's.