diff options
author | Rama Krishnan Raghupathy <ramarag@microsoft.com> | 2016-02-18 18:21:18 -0800 |
---|---|---|
committer | Rama Krishnan Raghupathy <ramarag@microsoft.com> | 2016-02-19 18:09:11 -0800 |
commit | f98fb85e72d0f24c58d9e54b8b3bff2c67f985fb (patch) | |
tree | a532e7803fbbe420807eb7d9390108554b02c46d /src/vm | |
parent | 01ffa08a2e4748e9826956ea961eacb227b6ee87 (diff) | |
download | coreclr-f98fb85e72d0f24c58d9e54b8b3bff2c67f985fb.tar.gz coreclr-f98fb85e72d0f24c58d9e54b8b3bff2c67f985fb.tar.bz2 coreclr-f98fb85e72d0f24c58d9e54b8b3bff2c67f985fb.zip |
This Change Adds initial Support for LongFiles in the VM,
They are:
1. Wrappers for OS APIs which take or return PATHS
2. Fixing the usage of following Api's:
GetEnvironmentVariableW
SearchPathW
GetShortPathNameW
GetLongPathNameW
GetModuleFileName
Work remaining:
Remove fixed size buffers in the VM
Diffstat (limited to 'src/vm')
-rw-r--r-- | src/vm/appdomain.cpp | 40 | ||||
-rw-r--r-- | src/vm/assemblynative.cpp | 8 | ||||
-rw-r--r-- | src/vm/ceemain.cpp | 89 | ||||
-rw-r--r-- | src/vm/codeman.cpp | 7 | ||||
-rw-r--r-- | src/vm/corhost.cpp | 7 | ||||
-rw-r--r-- | src/vm/dwbucketmanager.hpp | 15 | ||||
-rw-r--r-- | src/vm/dwreport.cpp | 208 | ||||
-rw-r--r-- | src/vm/dwreport.h | 2 | ||||
-rw-r--r-- | src/vm/eeconfig.cpp | 68 | ||||
-rw-r--r-- | src/vm/eepolicy.cpp | 6 | ||||
-rw-r--r-- | src/vm/eventreporter.cpp | 10 | ||||
-rw-r--r-- | src/vm/eventtrace.cpp | 16 | ||||
-rw-r--r-- | src/vm/mdaassistants.cpp | 10 | ||||
-rw-r--r-- | src/vm/peimage.cpp | 11 | ||||
-rw-r--r-- | src/vm/peimage.inl | 46 | ||||
-rw-r--r-- | src/vm/peimagelayout.cpp | 6 | ||||
-rw-r--r-- | src/vm/securitypolicy.cpp | 113 | ||||
-rw-r--r-- | src/vm/securitypolicy.h | 2 |
18 files changed, 362 insertions, 302 deletions
diff --git a/src/vm/appdomain.cpp b/src/vm/appdomain.cpp index 9ab8c7dbc0..a841423ace 100644 --- a/src/vm/appdomain.cpp +++ b/src/vm/appdomain.cpp @@ -4770,12 +4770,10 @@ void SystemDomain::GetDevpathW(__out_ecount_opt(1) LPWSTR* pDevpath, DWORD* pdwD if(m_fDevpath == FALSE) { DWORD dwPath = 0; - dwPath = WszGetEnvironmentVariable(APPENV_DEVPATH, 0, 0); + PathString m_pwDevpathholder; + dwPath = WszGetEnvironmentVariable(APPENV_DEVPATH, m_pwDevpathholder); if(dwPath) { - m_pwDevpath = (WCHAR*) new WCHAR[dwPath]; - m_dwDevpath = WszGetEnvironmentVariable(APPENV_DEVPATH, - m_pwDevpath, - dwPath); + m_pwDevpath = m_pwDevpathholder.GetCopyOfUnicodeString(); } else { RegKeyHolder userKey; @@ -13831,14 +13829,30 @@ DWORD* SetupCompatibilityFlags() SO_TOLERANT; } CONTRACTL_END; - WCHAR buf[2] = { '\0', '\0' }; + LPCWSTR buf; + bool return_null = true; FAULT_NOT_FATAL(); // we can simply give up - if (WszGetEnvironmentVariable(W("UnsupportedCompatSwitchesEnabled"), buf, COUNTOF(buf)) == 0) - return NULL; + BEGIN_SO_INTOLERANT_CODE_NO_THROW_CHECK_THREAD(SetLastError(COR_E_STACKOVERFLOW); return NULL;) + InlineSString<4> bufString; + + if (WszGetEnvironmentVariable(W("UnsupportedCompatSwitchesEnabled"), bufString) != 0) + { + buf = bufString.GetUnicode(); + if (buf[0] != '1' || buf[1] != '\0') + { + return_null = true; + } + else + { + return_null = false; + } + + } + END_SO_INTOLERANT_CODE - if (buf[0] != '1' || buf[1] != '\0') + if (return_null) return NULL; static const LPCWSTR rgFlagNames[] = { @@ -13852,17 +13866,21 @@ DWORD* SetupCompatibilityFlags() return NULL; ZeroMemory(pFlags, size * sizeof(DWORD)); + BEGIN_SO_INTOLERANT_CODE_NO_THROW_CHECK_THREAD(SetLastError(COR_E_STACKOVERFLOW); return NULL;) + InlineSString<4> bufEnvString; for (int i = 0; i < COUNTOF(rgFlagNames); i++) { - if (WszGetEnvironmentVariable(rgFlagNames[i], buf, COUNTOF(buf)) == 0) + if (WszGetEnvironmentVariable(rgFlagNames[i], bufEnvString) == 0) continue; + buf = bufEnvString.GetUnicode(); if (buf[0] != '1' || buf[1] != '\0') continue; pFlags[i / 32] |= 1 << (i % 32); } - + END_SO_INTOLERANT_CODE + return pFlags; } diff --git a/src/vm/assemblynative.cpp b/src/vm/assemblynative.cpp index 5720c201ed..c89e927404 100644 --- a/src/vm/assemblynative.cpp +++ b/src/vm/assemblynative.cpp @@ -2364,8 +2364,8 @@ void QCALLTYPE AssemblyNative::CreateVersionInfoResource(LPCWSTR pwzFilename, const void *pvData=0; // Pointer to the resource. ULONG cbData; // Size of the resource data. ULONG cbWritten; - WCHAR szFile[MAX_PATH_FNAME+1]; // File name for resource file. - WCHAR szPath[MAX_LONGPATH+1]; // Path name for resource file. + PathString szFile; // File name for resource file. + PathString szPath; // Path name for resource file. HandleHolder hFile; res.SetInfo(pwzFilename, @@ -2387,9 +2387,9 @@ void QCALLTYPE AssemblyNative::CreateVersionInfoResource(LPCWSTR pwzFilename, // messages including the path/file name</TODO> // Persist to a file. - if (!WszGetTempPath(MAX_LONGPATH, szPath)) + if (!WszGetTempPath(szPath)) COMPlusThrowWin32(); - if (!WszGetTempFileName(szPath, W("RES"), 0, szFile)) + if (!WszGetTempFileName(szPath.GetUnicode(), W("RES"), 0, szFile)) COMPlusThrowWin32(); hFile = WszCreateFile(szFile, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); diff --git a/src/vm/ceemain.cpp b/src/vm/ceemain.cpp index d6391056ab..e2419ac88f 100644 --- a/src/vm/ceemain.cpp +++ b/src/vm/ceemain.cpp @@ -2978,9 +2978,9 @@ static BOOL CacheCommandLine(__in LPWSTR pCmdLine, __in_opt LPWSTR* ArgvW) } if (ArgvW != NULL && ArgvW[0] != NULL) { - WCHAR wszModuleName[MAX_LONGPATH]; - WCHAR wszCurDir[MAX_LONGPATH]; - if (!WszGetCurrentDirectory(MAX_LONGPATH, wszCurDir)) + PathString wszModuleName; + PathString wszCurDir; + if (!WszGetCurrentDirectory(wszCurDir)) return FALSE; #ifdef _PREFAST_ @@ -2991,17 +2991,17 @@ static BOOL CacheCommandLine(__in LPWSTR pCmdLine, __in_opt LPWSTR* ArgvW) // usage of PathCombine is safe if we ensure that buffer specified by // parameter1 can accomodate buffers specified by paramater2, parameter3 // and one path separator - if (lstrlenW(wszCurDir) + lstrlenW(ArgvW[0]) + 1 >= COUNTOF(wszModuleName)) - return FALSE; + COUNT_T wszModuleName_len = wszCurDir.GetCount() + lstrlenW(ArgvW[0]); + WCHAR* wszModuleName_buf = wszModuleName.OpenUnicodeBuffer(wszModuleName_len); - if (PathCombine(wszModuleName, wszCurDir, ArgvW[0]) == NULL) + if (PathCombine(wszModuleName_buf, wszCurDir, ArgvW[0]) == NULL) return FALSE; - + wszModuleName.CloseBuffer(); #ifdef _PREFAST_ #pragma warning(pop) #endif - size_t len = wcslen(wszModuleName); + size_t len = wszModuleName.GetCount(); _ASSERT(g_pCachedModuleFileName== NULL); g_pCachedModuleFileName = new WCHAR[len+1]; wcscpy_s(g_pCachedModuleFileName, len+1, wszModuleName); @@ -3824,7 +3824,7 @@ BOOL STDMETHODCALLTYPE EEDllMain( // TRUE on success, FALSE on error. CoreClrCallbacks cccallbacks; cccallbacks.m_hmodCoreCLR = (HINSTANCE)g_pMSCorEE; cccallbacks.m_pfnIEE = IEE; - cccallbacks.m_pfnGetCORSystemDirectory = GetCORSystemDirectoryInternal; + cccallbacks.m_pfnGetCORSystemDirectory = GetCORSystemDirectoryInternaL; cccallbacks.m_pfnGetCLRFunction = GetCLRFunction; InitUtilcode(cccallbacks); @@ -4279,30 +4279,47 @@ static HRESULT InitializeIPCManager(void) { // We failed to create the IPC block because it has already been created. This means that // two mscoree's have been loaded into the process. - WCHAR strFirstModule[256]; - WCHAR strSecondModule[256]; - - // Get the name and path of the first loaded MSCOREE.DLL. - if (!hInstIPCBlockOwner || !WszGetModuleFileName(hInstIPCBlockOwner, strFirstModule, 256)) - wcscpy_s(strFirstModule, COUNTOF(strFirstModule), W("<Unknown>")); - - // Get the name and path of the second loaded MSCOREE.DLL. - if (!WszGetModuleFileName(g_pMSCorEE, strSecondModule, 256)) - wcscpy_s(strSecondModule, COUNTOF(strSecondModule), W("<Unknown>")); + PathString strFirstModule; + PathString strSecondModule; + EX_TRY + { + // Get the name and path of the first loaded MSCOREE.DLL. + if (!hInstIPCBlockOwner || !WszGetModuleFileName(hInstIPCBlockOwner, strFirstModule)) + strFirstModule.Set(W("<Unknown>")); + // Get the name and path of the second loaded MSCOREE.DLL. + if (!WszGetModuleFileName(g_pMSCorEE, strSecondModule)) + strSecondModule.Set(W("<Unknown>")); + } + EX_CATCH_HRESULT(hr); // Load the format strings for the title and the message body. EEMessageBoxCatastrophic(IDS_EE_TWO_LOADED_MSCOREE_MSG, IDS_EE_TWO_LOADED_MSCOREE_TITLE, strFirstModule, strSecondModule); goto errExit; } else { - if (!WszGetModuleFileName(GetModuleInst(), (PWSTR) - g_pIPCManagerInterface-> - GetInstancePath(), - MAX_LONGPATH)) + PathString temp; + if (!WszGetModuleFileName(GetModuleInst(), + temp + )) { hr = HRESULT_FROM_GetLastErrorNA(); } + else + { + EX_TRY + { + if (temp.GetCount() + 1 > MAX_LONGPATH) + { + hr = E_FAIL; + } + else + { + wcscpy_s((PWSTR)g_pIPCManagerInterface->GetInstancePath(),temp.GetCount() + 1,temp); + } + } + EX_CATCH_HRESULT(hr); + } } // Generate public IPCBlock for our PID. @@ -4915,11 +4932,12 @@ HRESULT CorCommandLine::ReadClickOnceEnvVariables() EX_TRY { // Find out if this is a ClickOnce application being activated. - DWORD cAppFullName = WszGetEnvironmentVariable(g_pwzClickOnceEnv_FullName, NULL, 0); + PathString m_pwszAppFullNameHolder; + DWORD cAppFullName = WszGetEnvironmentVariable(g_pwzClickOnceEnv_FullName, m_pwszAppFullNameHolder); if (cAppFullName > 0) { // get the application full name. - m_pwszAppFullName = new WCHAR[cAppFullName]; - WszGetEnvironmentVariable(g_pwzClickOnceEnv_FullName, m_pwszAppFullName, cAppFullName); + m_pwszAppFullName = m_pwszAppFullNameHolder.GetCopyOfUnicodeString(); + // reset the variable now that we read it so child processes // do not think they are a clickonce app. WszSetEnvironmentVariable(g_pwzClickOnceEnv_FullName, NULL); @@ -4933,7 +4951,8 @@ HRESULT CorCommandLine::ReadClickOnceEnvVariables() _itow_s(dwManifestPaths, buf.OpenUnicodeBuffer(size), size, 10); buf.CloseBuffer(); manifestFile.Append(buf); - if (WszGetEnvironmentVariable(manifestFile.GetUnicode(), NULL, 0) > 0) + SString temp; + if (WszGetEnvironmentVariable(manifestFile.GetUnicode(), temp) > 0) dwManifestPaths++; else break; @@ -4946,10 +4965,11 @@ HRESULT CorCommandLine::ReadClickOnceEnvVariables() _itow_s(i, buf.OpenUnicodeBuffer(size), size, 10); buf.CloseBuffer(); manifestFile.Append(buf); - DWORD cManifestPath = WszGetEnvironmentVariable(manifestFile.GetUnicode(), NULL, 0); + PathString m_ppwszManifestPathsHolder; + DWORD cManifestPath = WszGetEnvironmentVariable(manifestFile.GetUnicode(), m_ppwszManifestPathsHolder); if (cManifestPath > 0) { - m_ppwszManifestPaths[i] = new WCHAR[cManifestPath]; - WszGetEnvironmentVariable(manifestFile.GetUnicode(), m_ppwszManifestPaths[i], cManifestPath); + + m_ppwszManifestPaths[i] = m_ppwszManifestPathsHolder.GetCopyOfUnicodeString(); WszSetEnvironmentVariable(manifestFile.GetUnicode(), NULL); // reset the env. variable. } } @@ -4964,7 +4984,8 @@ HRESULT CorCommandLine::ReadClickOnceEnvVariables() _itow_s(dwActivationData, buf.OpenUnicodeBuffer(size), size, 10); buf.CloseBuffer(); activationData.Append(buf); - if (WszGetEnvironmentVariable(activationData.GetUnicode(), NULL, 0) > 0) + SString temp; + if (WszGetEnvironmentVariable(activationData.GetUnicode(), temp) > 0) dwActivationData++; else break; @@ -4977,10 +4998,10 @@ HRESULT CorCommandLine::ReadClickOnceEnvVariables() _itow_s(i, buf.OpenUnicodeBuffer(size), size, 10); buf.CloseBuffer(); activationData.Append(buf); - DWORD cActivationData = WszGetEnvironmentVariable(activationData.GetUnicode(), NULL, 0); + PathString m_ppwszActivationDataHolder; + DWORD cActivationData = WszGetEnvironmentVariable(activationData.GetUnicode(), m_ppwszActivationDataHolder); if (cActivationData > 0) { - m_ppwszActivationData[i] = new WCHAR[cActivationData]; - WszGetEnvironmentVariable(activationData.GetUnicode(), m_ppwszActivationData[i], cActivationData); + m_ppwszActivationData[i] = m_ppwszActivationDataHolder.GetCopyOfUnicodeString(); WszSetEnvironmentVariable(activationData.GetUnicode(), NULL); // reset the env. variable. } } diff --git a/src/vm/codeman.cpp b/src/vm/codeman.cpp index 9374a2c8a9..4f99539215 100644 --- a/src/vm/codeman.cpp +++ b/src/vm/codeman.cpp @@ -1386,10 +1386,12 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName, OUT HINSTANCE* phJit, OUT I HRESULT hr = E_FAIL; #ifdef FEATURE_MERGE_JIT_AND_ENGINE - WCHAR CoreClrFolder[MAX_LONGPATH + 1]; + PathString CoreClrFolderHolder; extern HINSTANCE g_hThisInst; - if (WszGetModuleFileName(g_hThisInst, CoreClrFolder, MAX_LONGPATH)) + if (WszGetModuleFileName(g_hThisInst, CoreClrFolderHolder)) { + DWORD len = CoreClrFolderHolder.GetCount(); + WCHAR* CoreClrFolder = CoreClrFolderHolder.OpenUnicodeBuffer(len); WCHAR *filePtr = wcsrchr(CoreClrFolder, DIRECTORY_SEPARATOR_CHAR_W); if (filePtr) { @@ -1401,6 +1403,7 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName, OUT HINSTANCE* phJit, OUT I hr = S_OK; } } + CoreClrFolderHolder.CloseBuffer(); } #else hr = g_pCLRRuntime->LoadLibrary(pwzJitName, phJit); diff --git a/src/vm/corhost.cpp b/src/vm/corhost.cpp index 2a7cf45249..f0e90291b7 100644 --- a/src/vm/corhost.cpp +++ b/src/vm/corhost.cpp @@ -2471,10 +2471,9 @@ HRESULT CorHost2::ExecuteMain( AppDomain *pDomain = GetAppDomain(); _ASSERTE(pDomain); - WCHAR wzExeFileName[_MAX_PATH]; - DWORD cchExeFileName = _MAX_PATH; - cchExeFileName = WszGetModuleFileName(nullptr, wzExeFileName, cchExeFileName); - if (cchExeFileName == _MAX_PATH) + PathString wzExeFileName; + + if (WszGetModuleFileName(nullptr, wzExeFileName) == 0) IfFailThrow(E_UNEXPECTED); LPWSTR wzExeSimpleFileName = nullptr; diff --git a/src/vm/dwbucketmanager.hpp b/src/vm/dwbucketmanager.hpp index 48746d4816..a3aef9b2a8 100644 --- a/src/vm/dwbucketmanager.hpp +++ b/src/vm/dwbucketmanager.hpp @@ -323,7 +323,6 @@ private: void FindFaultingMethodInfo(); OBJECTREF GetRealExceptionObject(); WCHAR* GetParamBufferForIndex(BucketParameterIndex paramIndex); - int CopyStringToBucket(__out_ecount(targetMaxLength) LPWSTR pTargetParam, int targetMaxLength, __in_z LPCWSTR pSource, bool cannonicalize = false); void LogParam(__in_z LPCWSTR paramValue, BucketParameterIndex paramIndex); protected: @@ -349,7 +348,7 @@ protected: public: BaseBucketParamsManager(GenericModeBlock* pGenericModeBlock, TypeOfReportedError typeOfError, PCODE initialFaultingPc, Thread* pFaultingThread, OBJECTREF* pThrownException); - + static int CopyStringToBucket(__out_ecount(targetMaxLength) LPWSTR pTargetParam, int targetMaxLength, __in_z LPCWSTR pSource, bool cannonicalize = false); // function that consumers should call to populate the GMB virtual void PopulateBucketParameters() = 0; }; @@ -485,10 +484,10 @@ void BaseBucketParamsManager::GetAppName(__out_ecount(maxLength) WCHAR* targetPa CONTRACTL_END; HMODULE hModule = WszGetModuleHandle(NULL); - WCHAR appPath[MAX_LONGPATH]; - DWORD cchAppPath = NumItems(appPath); + PathString appPath; + - if (GetCurrentModuleFileName(appPath, &cchAppPath) == S_OK) + if (GetCurrentModuleFileName(appPath) == S_OK) { CopyStringToBucket(targetParam, maxLength, appPath); } @@ -509,13 +508,13 @@ void BaseBucketParamsManager::GetAppVersion(__out_ecount(maxLength) WCHAR* targe CONTRACTL_END; HMODULE hModule = WszGetModuleHandle(NULL); - WCHAR appPath[MAX_LONGPATH]; - DWORD cchAppPath = NumItems(appPath); + PathString appPath; + WCHAR verBuf[23] = {0}; USHORT major, minor, build, revision; - if ((GetCurrentModuleFileName(appPath, &cchAppPath) == S_OK) && SUCCEEDED(DwGetFileVersionInfo(appPath, major, minor, build, revision))) + if ((GetCurrentModuleFileName(appPath) == S_OK) && SUCCEEDED(DwGetFileVersionInfo(appPath, major, minor, build, revision))) { _snwprintf_s(targetParam, maxLength, diff --git a/src/vm/dwreport.cpp b/src/vm/dwreport.cpp index 15a58c0701..77669b2f14 100644 --- a/src/vm/dwreport.cpp +++ b/src/vm/dwreport.cpp @@ -214,15 +214,6 @@ BOOL RegisterOutOfProcessWatsonCallbacks() CONTRACTL_END; WCHAR wszDACName[] = MAIN_DAC_MODULE_NAME_W W(".dll"); - WCHAR wszDACPath[MAX_LONGPATH]; - DWORD dwSize = 0; - - if ((FAILED(::GetCORSystemDirectoryInternal(wszDACPath, NumItems(wszDACPath), &dwSize))) || - (wcscat_s(wszDACPath, _countof(wszDACPath), wszDACName) != 0)) - { - return FALSE; - } - WerModuleHolder hWerModule(WER_MODULE_NAME_W); #ifdef FEATURE_CORESYSTEM @@ -250,8 +241,23 @@ BOOL RegisterOutOfProcessWatsonCallbacks() { return FALSE; } + HRESULT hr = S_OK; - HRESULT hr = (*pFnWerRegisterRuntimeExceptionModule)(wszDACPath, (PDWORD)g_pMSCorEE); + EX_TRY + { + PathString wszDACPath; + if (SUCCEEDED(::GetCORSystemDirectoryInternaL(wszDACPath))) + { + wszDACPath.Append(wszDACName); + hr = (*pFnWerRegisterRuntimeExceptionModule)(wszDACPath, (PDWORD)g_pMSCorEE); + } + else { + hr = E_FAIL; + } + + } + EX_CATCH_HRESULT(hr); + if (FAILED(hr)) { STRESS_LOG0(LF_STARTUP, @@ -562,9 +568,9 @@ HRESULT DwCheckCompany( // S_OK or error. // None //------------------------------------------------------------------------------ int DwGetAppDescription( // Number of characters written. - __in_z LPWSTR wszFilePath, // Path to the executable. - __inout_ecount(cchBuf) WCHAR *pBuf, // Put description here. - int cchBuf) // Size of buf, wide chars. + __in_z LPCWSTR wszFilePath, // Path to the executable. + SString& pBuf // Put description here. + ) // Size of buf, wide chars. { CONTRACTL { @@ -663,8 +669,17 @@ int DwGetAppDescription( // Number of characters written. } // Copy back the description. - size = (int)size > cchBuf-1 ? cchBuf-1 : size; - wcsncpy_s(pBuf, cchBuf, fileDescription, size); + EX_TRY + { + wcsncpy_s(pBuf.OpenUnicodeBuffer(size), size, fileDescription, size); + pBuf.CloseBuffer(size); + } + EX_CATCH + { + size = 0; + } + EX_END_CATCH(SwallowAllExceptions); + return size; } // int DwGetAppDescription() @@ -685,7 +700,7 @@ int DwGetAppDescription( // Number of characters written. // None //------------------------------------------------------------------------------ int DwGetAssemblyVersion( // Number of characters written. - __in_z LPWSTR wszFilePath, // Path to the executable. + __in_z LPCWSTR wszFilePath, // Path to the executable. __inout_ecount(cchBuf) WCHAR *pBuf, // Put description here. int cchBuf) // Size of buf, wide chars. { @@ -1469,88 +1484,99 @@ BOOL RunWatson( memset(&startupInfo, 0, sizeof(STARTUPINFOW)); startupInfo.cb = sizeof(STARTUPINFOW); + HRESULT hr = S_OK; + PathString watsonAppName; + PathString watsonCommandLine; + EX_TRY + { + do + { - WCHAR watsonAppName[MAX_LONGPATH]; - WCHAR watsonCommandLine[MAX_LONGPATH+1]; - { -#if !defined(FEATURE_CORECLR) - // Use the version of DW20.exe that lives in the system directory. - DWORD ret; + - if (FAILED(GetCORSystemDirectoryInternal(watsonAppName, NumItems(watsonAppName), &ret))) - { - return false; - } - if (wcsncat_s(watsonAppName, NumItems(watsonAppName), kWatsonImageNameOnVista, _TRUNCATE) != 0) - { - return false; - } -#else // FEATURE_CORECLR - HKEYHolder hKey; - // Look for key \\HKLM\Software\Microsoft\PCHealth\ErrorReporting\DW\Installed" - DWORD ret = WszRegOpenKeyEx(HKEY_LOCAL_MACHINE, - kWatsonPath, - 0, - KEY_READ | kWatsonRegKeyOptions, - &hKey); - - if (ERROR_SUCCESS != ret) { - return false; - } + #if !defined(FEATURE_CORECLR) + // Use the version of DW20.exe that lives in the system directory. + DWORD ret; + if (FAILED(GetCORSystemDirectoryInternaL(watsonAppName))) + { + hr = E_FAIL; + break; + } + watsonCommandLine.Set(watsonAppName); + watsonCommandLine.Append(kWatsonImageNameOnVista); + + #else // FEATURE_CORECLR + HKEYHolder hKey; + // Look for key \\HKLM\Software\Microsoft\PCHealth\ErrorReporting\DW\Installed" + DWORD ret = WszRegOpenKeyEx(HKEY_LOCAL_MACHINE, + kWatsonPath, + 0, + KEY_READ | kWatsonRegKeyOptions, + &hKey); + + if (ERROR_SUCCESS != ret) + { + hr = E_FAIL; + break; + } - // Look in ...\DW\Installed for dw0200 (dw0201 on ia64). This will be - // the full path to the executable. - DWORD size = NumItems(watsonAppName); - ret = WszRegQueryValueEx(hKey, - kWatsonValue, - NULL, - NULL, - reinterpret_cast< LPBYTE >(watsonAppName), - &size); - - if (ERROR_SUCCESS != ret) - { - return false; - } -#endif // ! FEATURE_CORECLR + // Look in ...\DW\Installed for dw0200 (dw0201 on ia64). This will be + // the full path to the executable. + + ClrRegReadString(hKey, kWatsonValue, watsonAppName); + + #endif // ! FEATURE_CORECLR - _snwprintf_s(watsonCommandLine, - NumItems(watsonCommandLine)-1, - _TRUNCATE, - W("dw20.exe -x -s %lu"), - PtrToUlong(hWatsonSharedMemory)); - watsonCommandLine[NumItems(watsonCommandLine) - 1] = W('\0'); + COUNT_T len = watsonCommandLine.GetCount(); + WCHAR* buffer = watsonCommandLine.OpenUnicodeBuffer(len); + _snwprintf_s(buffer, + len, + _TRUNCATE, + W("dw20.exe -x -s %lu"), + PtrToUlong(hWatsonSharedMemory)); + watsonCommandLine.CloseBuffer(); + + } + } while (false); } + EX_CATCH_HRESULT(hr); + if (hr != S_OK) { - BOOL ret = WszCreateProcess(watsonAppName, - watsonCommandLine, - NULL, - NULL, - TRUE, - NULL, - NULL, - NULL, - &startupInfo, - &processInformation); + return false; + } - if (FALSE == ret) { - // - // Watson failed to start up. - // - // This can happen if e.g. Watson wasn't installed on the machine. - // - HRESULT hr = HRESULT_FROM_GetLastErrorNA(); - return false; + BOOL ret = WszCreateProcess(watsonAppName, + watsonCommandLine, + NULL, + NULL, + TRUE, + NULL, + NULL, + NULL, + &startupInfo, + &processInformation); + + if (FALSE == ret) + { + // + // Watson failed to start up. + // + // This can happen if e.g. Watson wasn't installed on the machine. + // + return E_FAIL; + + } + } - } + // Wait for watson to finish. // @@ -2426,9 +2452,11 @@ FaultReportResult DoFaultReportWorker( // Was Watson attempted, successful? pWatsonSharedMemory->bfmsoctdsLetRun = offerFlags; { + PathString wzModuleFileName; DWORD dwRet = WszGetModuleFileName(NULL, - pWatsonSharedMemory->wzModuleFileName, - NumItems(pWatsonSharedMemory->wzModuleFileName)); + wzModuleFileName); + BaseBucketParamsManager::CopyStringToBucket(pWatsonSharedMemory->wzModuleFileName, NumItems(pWatsonSharedMemory->wzModuleFileName), wzModuleFileName); + _ASSERTE(0 != dwRet); if (0 == dwRet) { @@ -2455,24 +2483,24 @@ FaultReportResult DoFaultReportWorker( // Was Watson attempted, successful? // do this just by using the executable name. // { - WCHAR buf[_MAX_PATH]; // Buffer for path for description. - WCHAR *pName = buf; // Pointer to filename or description. + PathString buf; // Buffer for path for description. + LPCWSTR pName ; // Pointer to filename or description. int size; // Size of description. HMODULE hModule; // Handle to module. DWORD result; // Return code // Get module name. hModule = WszGetModuleHandle(NULL); - result = WszGetModuleFileName(hModule, buf, NumItems(buf)); + result = WszGetModuleFileName(hModule, buf); if (result == 0) { // Couldn't get module name. This should never happen. - wcscpy_s(buf, COUNTOF(buf), W("<<unknown>>")); + pName = W("<<unknown>>"); } else { // re-use the buf for pathname and description. - size = DwGetAppDescription(buf, buf, NumItems(buf)); - + size = DwGetAppDescription(buf, buf); + pName = buf.GetUnicode(); // If the returned size was zero, buf wasn't changed, and still contains the path. // find just the filename part. if (size == 0) diff --git a/src/vm/dwreport.h b/src/vm/dwreport.h index a2750cefe7..44306689ea 100644 --- a/src/vm/dwreport.h +++ b/src/vm/dwreport.h @@ -58,7 +58,7 @@ BOOL IsWatsonEnabled(); BOOL RegisterOutOfProcessWatsonCallbacks(); int DwGetAssemblyVersion( // Number of characters written. - __in_z LPWSTR wszFilePath, // Path to the executable. + __in_z LPCWSTR wszFilePath, // Path to the executable. __inout_ecount(cchBuf) WCHAR *pBuf, // Put description here. int cchBuf); diff --git a/src/vm/eeconfig.cpp b/src/vm/eeconfig.cpp index e322a63f5e..973a4f4235 100644 --- a/src/vm/eeconfig.cpp +++ b/src/vm/eeconfig.cpp @@ -835,12 +835,12 @@ HRESULT EEConfig::sync() { bGCStressAndHeapVerifyAllowed = false; - WCHAR wszFileName[_MAX_PATH]; - if (WszGetModuleFileName(NULL, wszFileName, _MAX_PATH) != 0) + PathString wszFileName; + if (WszGetModuleFileName(NULL, wszFileName) != 0) { // just keep the name - LPWSTR pwszName = wcsrchr(wszFileName, W('\\')); - pwszName = (pwszName == NULL) ? wszFileName : (pwszName + 1); + LPCWSTR pwszName = wcsrchr(wszFileName, W('\\')); + pwszName = (pwszName == NULL) ? wszFileName.GetUnicode() : (pwszName + 1); if (SString::_wcsicmp(pwszName,pszGCStressExe) == 0) { @@ -1619,46 +1619,62 @@ HRESULT EEConfig::SetupConfiguration() // AppX process check to make sure no app.config file // exists unless launched with AO_DESIGNMODE. // ---------------------------------------------------- + + do { - WCHAR wzProcExe[_MAX_PATH]; - size_t cchProcExe = COUNTOF(wzProcExe); - - // Get name of file used to create process - if (g_pCachedModuleFileName) - { - IfFailRet(StringCchCopy(wzProcExe, COUNTOF(wzProcExe), g_pCachedModuleFileName)); - IfFailRet(StringCchLength(wzProcExe, COUNTOF(wzProcExe), &cchProcExe)); - } - else + size_t cchProcExe=0; + PathString wzProcExe; + EX_TRY { - cchProcExe = WszGetModuleFileName(NULL, wzProcExe, COUNTOF(wzProcExe)); - if (cchProcExe == 0) + + + // Get name of file used to create process + if (g_pCachedModuleFileName) { - return HRESULT_FROM_GetLastError(); + wzProcExe.Set(g_pCachedModuleFileName); + cchProcExe = wzProcExe.GetCount(); } - } + else + { + cchProcExe = WszGetModuleFileName(NULL, wzProcExe); - if (cchProcExe != 0) - { - IfFailRet(StringCchCat(wzProcExe, COUNTOF(wzProcExe), CONFIGURATION_EXTENSION)); + if (cchProcExe == 0) + { + hr = HRESULT_FROM_GetLastError(); + break; + } + } - if (AppX::IsAppXProcess() && !AppX::IsAppXDesignMode()) + if (cchProcExe != 0) { - if (clr::fs::Path::Exists(wzProcExe)) + wzProcExe.Append(CONFIGURATION_EXTENSION); + + if (AppX::IsAppXProcess() && !AppX::IsAppXDesignMode()) { - return CLR_E_APP_CONFIG_NOT_ALLOWED_IN_APPX_PROCESS; + if (clr::fs::Path::Exists(wzProcExe)) + { + hr = CLR_E_APP_CONFIG_NOT_ALLOWED_IN_APPX_PROCESS; + break; + } } } - + } + EX_CATCH_HRESULT(hr); + if (cchProcExe != 0) + { IfFailParseError(wzProcExe, true, AppendConfigurationFile(wzProcExe, version)); // We really should return a failure hresult if the app config file is bad, but that // would be a breaking change. Not sure if it's worth it yet. hr = S_OK; + break; } - } + } while (false); + + if (hr != S_OK) + return hr; // ---------------------------------------------------- // Import machine.config, if needed. // ---------------------------------------------------- diff --git a/src/vm/eepolicy.cpp b/src/vm/eepolicy.cpp index c67d06d596..8c3f2ec625 100644 --- a/src/vm/eepolicy.cpp +++ b/src/vm/eepolicy.cpp @@ -530,11 +530,11 @@ void SafeExitProcess(UINT exitCode, BOOL fAbort = FALSE, ShutdownCompleteAction if (CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_BreakOnBadExit)) { // Workaround for aspnet - WCHAR wszFilename[_MAX_PATH]; + PathString wszFilename; bool bShouldAssert = true; - if (WszGetModuleFileName(NULL, wszFilename, _MAX_PATH)) + if (WszGetModuleFileName(NULL, wszFilename)) { - _wcslwr_s(wszFilename, COUNTOF(wszFilename)); + wszFilename.LowerCase(); if (wcsstr(wszFilename, W("aspnet_compiler"))) { diff --git a/src/vm/eventreporter.cpp b/src/vm/eventreporter.cpp index e07a6401cd..567f4f5d51 100644 --- a/src/vm/eventreporter.cpp +++ b/src/vm/eventreporter.cpp @@ -47,8 +47,8 @@ EventReporter::EventReporter(EventReporterType type) m_eventType = type; HMODULE hModule = WszGetModuleHandle(NULL); - WCHAR appPath[MAX_LONGPATH]; - DWORD ret = WszGetModuleFileName(hModule, appPath, NumItems(appPath)); + PathString appPath; + DWORD ret = WszGetModuleFileName(hModule, appPath); fBufferFull = FALSE; @@ -65,7 +65,7 @@ EventReporter::EventReporter(EventReporterType type) if (ret != 0) { // If app name has a '\', consider the part after that; otherwise consider whole name. - WCHAR* appName = wcsrchr(appPath, W('\\')); + LPCWSTR appName = wcsrchr(appPath, W('\\')); appName = appName ? appName+1 : appPath; m_Description.Append(appName); m_Description.Append(W("\n")); @@ -808,8 +808,8 @@ void EventReporter::GetCoreCLRInstanceProductVersion(DWORD * pdwMajor, DWORD * p _ASSERTE(hModRuntime != NULL); // Get the path to the runtime - WCHAR runtimePath[MAX_LONGPATH]; - DWORD ret = WszGetModuleFileName(hModRuntime, runtimePath, NumItems(runtimePath)); + PathString runtimePath; + DWORD ret = WszGetModuleFileName(hModRuntime, runtimePath); if (ret != 0) { // Got the path - get the file version from the path diff --git a/src/vm/eventtrace.cpp b/src/vm/eventtrace.cpp index e6a25cc853..5e35f9a2b8 100644 --- a/src/vm/eventtrace.cpp +++ b/src/vm/eventtrace.cpp @@ -4869,7 +4869,7 @@ VOID ETW::InfoLog::RuntimeInformation(INT32 type) PCWSTR szDtraceOutput1=W(""),szDtraceOutput2=W(""); UINT8 startupMode = 0; UINT startupFlags = 0; - WCHAR dllPath[MAX_LONGPATH+1] = {0}; + PathString dllPath; UINT8 Sku = 0; _ASSERTE(g_fEEManagedEXEStartup || //CLR started due to a managed exe g_fEEIJWStartup || //CLR started as a mixed mode Assembly @@ -4899,7 +4899,7 @@ VOID ETW::InfoLog::RuntimeInformation(INT32 type) LPCGUID comGUID=&g_EEComObjectGuid; PCWSTR lpwszCommandLine = W(""); - PCWSTR lpwszRuntimeDllPath = (PCWSTR)dllPath; + #ifndef FEATURE_CORECLR startupFlags = CorHost2::GetStartupFlags(); @@ -4954,12 +4954,12 @@ VOID ETW::InfoLog::RuntimeInformation(INT32 type) startupMode = ETW::InfoLog::InfoStructs::Other; } - _ASSERTE (NumItems(dllPath) > MAX_LONGPATH); + // if WszGetModuleFileName fails, we return an empty string - if (!WszGetModuleFileName(GetCLRModule(), dllPath, MAX_LONGPATH)) { - dllPath[0] = 0; + if (!WszGetModuleFileName(GetCLRModule(), dllPath)) { + dllPath.Set(W("\0")); } - dllPath[MAX_LONGPATH] = 0; + if(type == ETW::InfoLog::InfoStructs::Callback) { @@ -4977,7 +4977,7 @@ VOID ETW::InfoLog::RuntimeInformation(INT32 type) startupMode, lpwszCommandLine, comGUID, - lpwszRuntimeDllPath ); + dllPath ); } else { @@ -4995,7 +4995,7 @@ VOID ETW::InfoLog::RuntimeInformation(INT32 type) startupMode, lpwszCommandLine, comGUID, - lpwszRuntimeDllPath ); + dllPath ); } } } EX_CATCH { } EX_END_CATCH(SwallowAllExceptions); diff --git a/src/vm/mdaassistants.cpp b/src/vm/mdaassistants.cpp index de81a82f83..cc598c0a6c 100644 --- a/src/vm/mdaassistants.cpp +++ b/src/vm/mdaassistants.cpp @@ -995,12 +995,12 @@ void MdaPInvokeLog::LogPInvoke(NDirectMethodDesc* pMD, HINSTANCE hMod) StackSString sszEntryPoint; sszEntryPoint.SetUTF8(pMD->GetEntrypointName()); - WCHAR szDllFullName[_MAX_PATH] = {0}; + PathString szDllFullName ; WCHAR szDrive[_MAX_PATH] = {0}; WCHAR szPath[_MAX_PATH] = {0}; WCHAR szFileName[_MAX_PATH] = {0}; WCHAR szExt[_MAX_PATH] = {0}; - WszGetModuleFileName(hMod, szDllFullName, _MAX_PATH); + WszGetModuleFileName(hMod, szDllFullName); SplitPath(szDllFullName, szDrive, _MAX_PATH, szPath, _MAX_PATH, szFileName, _MAX_PATH, szExt, _MAX_PATH); StackSString sszDllName; @@ -1869,16 +1869,14 @@ void MdaLoaderLock::ReportViolation(HINSTANCE hInst) MdaXmlMessage msg(this->AsMdaAssistant(), TRUE, &pXml); DWORD cName = 0; - WCHAR szName[_MAX_PATH * 2]; + PathString szName; if (hInst) { - cName = _MAX_PATH * 2 - 1; - cName = WszGetModuleFileName(hInst, szName, cName); + cName = WszGetModuleFileName(hInst, szName); } if (cName) { - szName[cName] = W('\0'); msg.SendMessagef(MDARC_LOADER_LOCK_DLL, szName); } else diff --git a/src/vm/peimage.cpp b/src/vm/peimage.cpp index 27904ff476..cb1dd50c9d 100644 --- a/src/vm/peimage.cpp +++ b/src/vm/peimage.cpp @@ -422,15 +422,8 @@ void PEImage::GetPathFromDll(HINSTANCE hMod, SString &result) } CONTRACTL_END; - DWORD ret; - DWORD length = MAX_LONGPATH; - do - { - WCHAR *buffer = result.OpenUnicodeBuffer(length); - ret = WszGetModuleFileName(hMod, buffer, length); - result.CloseBuffer(ret); - length *= 2; - } while (ret == 0); + WszGetModuleFileName(hMod, result); + } #endif // !FEATURE_PAL diff --git a/src/vm/peimage.inl b/src/vm/peimage.inl index 343b2bbbd9..c2f6957ba0 100644 --- a/src/vm/peimage.inl +++ b/src/vm/peimage.inl @@ -592,25 +592,9 @@ inline PTR_PEImage PEImage::FindByLongPath(LPCWSTR pPath) } CONTRACTL_END; - InlineSString<MAX_PATH> sLongPath; - // Note: GetLongPathName return the number of characters written NOT INCLUDING the - // null character on success, and on failure returns the buffer size required - // INCLUDING the null. This means the result must not be equal to MAX_PATH - - // it must be greater or less then. - COUNT_T nLen = WszGetLongPathName(pPath, sLongPath.OpenUnicodeBuffer(MAX_PATH-1), MAX_PATH); - CONSISTENCY_CHECK(nLen != MAX_PATH); - - // If this was insufficient buffer, then try again with a reallocated buffer - if (nLen > MAX_PATH) - { - // Close the buffer before reopening - sLongPath.CloseBuffer(); - INDEBUG(SIZE_T nOldLen = nLen;) - nLen = WszGetLongPathName(pPath, sLongPath.OpenUnicodeBuffer(nLen-1), nLen); - CONSISTENCY_CHECK(nLen == (nOldLen - 1)); - } - sLongPath.CloseBuffer(nLen); - + PathString sLongPath; + COUNT_T nLen = WszGetLongPathName(pPath, sLongPath); + // Check for any kind of error other than an insufficient buffer result. if (nLen == 0) { @@ -619,7 +603,7 @@ inline PTR_PEImage PEImage::FindByLongPath(LPCWSTR pPath) ThrowHR(hr); return (PEImage*)INVALIDENTRY; } - return FindByPath(sLongPath); + return FindByPath(sLongPath.GetUnicode()); } /*static*/ @@ -634,24 +618,8 @@ inline PTR_PEImage PEImage::FindByShortPath(LPCWSTR pPath) } CONTRACTL_END; - InlineSString<MAX_PATH> sShortPath; - // Note: GetLongPathName return the number of characters written NOT INCLUDING the - // null character on success, and on failure returns the buffer size required - // INCLUDING the null. This means the result must not be equal to MAX_PATH - - // it must be greater or less then. - COUNT_T nLen = WszGetShortPathName(pPath, sShortPath.OpenUnicodeBuffer(MAX_PATH-1), MAX_PATH); - CONSISTENCY_CHECK(nLen != MAX_PATH); - - // If this was insufficient buffer, then try again with a reallocated buffer - if (nLen > MAX_PATH) - { - // Close the buffer before reopening - sShortPath.CloseBuffer(); - INDEBUG(SIZE_T nOldLen = nLen;) - nLen = WszGetShortPathName(pPath, sShortPath.OpenUnicodeBuffer(nLen-1), nLen); - CONSISTENCY_CHECK(nLen == (nOldLen - 1)); - } - sShortPath.CloseBuffer(nLen); + PathString sShortPath; + COUNT_T nLen = WszGetShortPathName(pPath, sShortPath); // Check for any kind of error other than an insufficient buffer result. if (nLen == 0) @@ -661,7 +629,7 @@ inline PTR_PEImage PEImage::FindByShortPath(LPCWSTR pPath) ThrowHR(hr); return (PEImage*)INVALIDENTRY; } - return FindByPath(sShortPath); + return FindByPath(sShortPath.GetUnicode()); } #endif // !FEATURE_CORECLR diff --git a/src/vm/peimagelayout.cpp b/src/vm/peimagelayout.cpp index 3868386860..8fdf554557 100644 --- a/src/vm/peimagelayout.cpp +++ b/src/vm/peimagelayout.cpp @@ -319,9 +319,9 @@ RawImageLayout::RawImageLayout(const void *mapped, PEImage* pOwner, BOOL bTakeOw if (bTakeOwnership) { #ifndef FEATURE_PAL - WCHAR wszDllName[MAX_LONGPATH]; - WszGetModuleFileName((HMODULE)mapped, wszDllName, MAX_LONGPATH); - wszDllName[MAX_LONGPATH - 1] = W('\0'); + PathString wszDllName; + WszGetModuleFileName((HMODULE)mapped, wszDllName); + m_LibraryHolder=CLRLoadLibraryEx(wszDllName,NULL,GetLoadWithAlteredSearchPathFlag()); #else // !FEATURE_PAL _ASSERTE(!"bTakeOwnership Should not be used on FEATURE_PAL"); diff --git a/src/vm/securitypolicy.cpp b/src/vm/securitypolicy.cpp index 082be54f88..fe1da90b8d 100644 --- a/src/vm/securitypolicy.cpp +++ b/src/vm/securitypolicy.cpp @@ -1,9 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. -// - -// +//The .NET Foundation licenses this file to you under the MIT license. +//See the LICENSE file in the project root for more information. #include "common.h" @@ -676,12 +673,11 @@ void QCALLTYPE SecurityPolicy::_GetLongPathName(LPCWSTR wszPath, QCall::StringHa BEGIN_QCALL; #if !defined(PLATFORM_UNIX) - WCHAR wszBuffer[MAX_LONGPATH + 1]; - ZeroMemory(wszBuffer, sizeof(wszBuffer)); + PathString wszBuffer; - if (SecurityPolicy::GetLongPathNameHelper( wszPath, wszBuffer, MAX_LONGPATH ) != 0) + if (SecurityPolicy::GetLongPathNameHelper( wszPath, wszBuffer ) != 0) { - retLongPath.Set( wszBuffer ); + retLongPath.Set( wszBuffer.GetUnicode() ); } #endif // !PLATFORM_UNIX @@ -689,15 +685,15 @@ void QCALLTYPE SecurityPolicy::_GetLongPathName(LPCWSTR wszPath, QCall::StringHa } #if !defined(PLATFORM_UNIX) -size_t SecurityPolicy::GetLongPathNameHelper( const WCHAR* wszShortPath, __inout_ecount(cchBuffer) __inout_z WCHAR* wszBuffer, DWORD cchBuffer ) +size_t GetLongPathNameHelperthatThrows(const WCHAR* wszShortPath, SString& wszBuffer) { - CONTRACTL { - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; + CONTRACTL{ + THROWS; + GC_NOTRIGGER; + MODE_ANY; } CONTRACTL_END; - DWORD size = WszGetLongPathName(wszShortPath, wszBuffer, cchBuffer); + DWORD size = WszGetLongPathName(wszShortPath, wszBuffer); if (size == 0) { @@ -707,66 +703,87 @@ size_t SecurityPolicy::GetLongPathNameHelper( const WCHAR* wszShortPath, __inout // trying GetLongPathName on every subdirectory until // it succeeds or we run out of string. - WCHAR wszIntermediateBuffer[MAX_LONGPATH]; + size_t len = wcslen(wszShortPath); + NewArrayHolder<WCHAR> wszIntermediateBuffer = new (nothrow) WCHAR[len + 1]; - if (wcslen( wszShortPath ) >= MAX_LONGPATH) + if (wszIntermediateBuffer == NULL) + { return 0; + } - wcscpy_s( wszIntermediateBuffer, COUNTOF(wszIntermediateBuffer), wszShortPath ); + wcscpy_s(wszIntermediateBuffer, len + 1, wszShortPath); - size_t index = wcslen( wszIntermediateBuffer ); + size_t index = len; do { - while (index > 0 && (wszIntermediateBuffer[index-1] != W('\\') && wszIntermediateBuffer[index-1] != W('/'))) + while (index > 0 && (wszIntermediateBuffer[index - 1] != W('\\') && wszIntermediateBuffer[index - 1] != W('/'))) --index; if (index == 0) break; - #ifdef _PREFAST_ - #pragma prefast(push) - #pragma prefast(disable:26001, "suppress prefast warning about underflow by doing index-1 which is checked above.") - #endif // _PREFAST_ - - wszIntermediateBuffer[index-1] = W('\0'); +#ifdef _PREFAST_ +#pragma prefast(push) +#pragma prefast(disable:26001, "suppress prefast warning about underflow by doing index-1 which is checked above.") +#endif // _PREFAST_ + + wszIntermediateBuffer[index - 1] = W('\0'); - #ifdef _PREFAST_ - #pragma prefast(pop) - #endif +#ifdef _PREFAST_ +#pragma prefast(pop) +#endif - size = WszGetLongPathName(wszIntermediateBuffer, wszBuffer, MAX_LONGPATH); + size = WszGetLongPathName(wszIntermediateBuffer, wszBuffer); if (size != 0) { - size_t sizeBuffer = wcslen( wszBuffer ); - if (sizeBuffer + wcslen( &wszIntermediateBuffer[index] ) > MAX_LONGPATH - 2) - { - return 0; - } - else - { - if (wszBuffer[sizeBuffer-1] != W('\\') && wszBuffer[sizeBuffer-1] != W('/')) - wcscat_s( wszBuffer, cchBuffer, W("\\") ); - wcscat_s( wszBuffer, cchBuffer, &wszIntermediateBuffer[index] ); - return (DWORD)wcslen( wszBuffer ); - } + int sizeBuffer = wszBuffer.GetCount(); + + if (wszBuffer[sizeBuffer - 1] != W('\\') && wszBuffer[sizeBuffer - 1] != W('/')) + wszBuffer.Append(W("\\")); + + wszBuffer.Append(&wszIntermediateBuffer[index]); + + + return (DWORD)wszBuffer.GetCount(); + } - } - while( true ); + } while (true); return 0; } - else if (size > MAX_LONGPATH) + else { - return 0; + return (DWORD)wszBuffer.GetCount(); } - else +} +size_t SecurityPolicy::GetLongPathNameHelper(const WCHAR* wszShortPath, SString& wszBuffer) +{ + CONTRACTL{ + NOTHROW; + GC_NOTRIGGER; + MODE_ANY; + } CONTRACTL_END; + + HRESULT hr = S_OK; + size_t retval = 0; + + EX_TRY { - return wcslen( wszBuffer ); + retval = GetLongPathNameHelperthatThrows(wszShortPath,wszBuffer); } + EX_CATCH_HRESULT(hr); + + if (hr != S_OK) + { + retval = 0; + } + + return retval; } + #endif // !PLATFORM_UNIX void QCALLTYPE SecurityPolicy::GetDeviceName(LPCWSTR wszDriveLetter, QCall::StringHandleOnStack retDeviceName) diff --git a/src/vm/securitypolicy.h b/src/vm/securitypolicy.h index cf2b10f21c..ba77bcbda8 100644 --- a/src/vm/securitypolicy.h +++ b/src/vm/securitypolicy.h @@ -198,7 +198,7 @@ namespace SecurityPolicy BOOL WasStrongNameEvidenceUsed(OBJECTREF evidence); #endif // Like WszGetLongPathName, but it works with nonexistant files too - size_t GetLongPathNameHelper( const WCHAR* wszShortPath, __inout_ecount(cchBuffer) __inout_z WCHAR* wszBuffer, DWORD cchBuffer ); + size_t GetLongPathNameHelper( const WCHAR* wszShortPath, SString& wszBuffer); #ifdef FEATURE_CAS_POLICY extern CrstStatic s_crstPolicyInit; |