From: Gaurav Khanna Date: Wed, 26 Apr 2017 23:53:58 +0000 (-0700) Subject: Fix filename display in exception messages (#11238) X-Git-Tag: accepted/tizen/base/20180629.140029~1259 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0afaf64d63d27ea5eaa3878b2e638d0c62028195;p=platform%2Fupstream%2Fcoreclr.git Fix filename display in exception messages (#11238) --- diff --git a/src/mscorlib/src/System/IO/FileLoadException.CoreCLR.cs b/src/mscorlib/src/System/IO/FileLoadException.CoreCLR.cs index f641567..d4ce9a9 100644 --- a/src/mscorlib/src/System/IO/FileLoadException.CoreCLR.cs +++ b/src/mscorlib/src/System/IO/FileLoadException.CoreCLR.cs @@ -27,7 +27,10 @@ namespace System.IO GetFileLoadExceptionMessage(hResult, JitHelpers.GetStringHandleOnStack(ref format)); string message = null; - GetMessageForHR(hResult, JitHelpers.GetStringHandleOnStack(ref message)); + if (hResult == System.__HResults.COR_E_BADEXEFORMAT) + message = SR.Arg_BadImageFormatException; + else + GetMessageForHR(hResult, JitHelpers.GetStringHandleOnStack(ref message)); return string.Format(CultureInfo.CurrentCulture, format, fileName, message); } diff --git a/src/mscorlib/src/System/__HResults.cs b/src/mscorlib/src/System/__HResults.cs index e4183f6..0592d81 100644 --- a/src/mscorlib/src/System/__HResults.cs +++ b/src/mscorlib/src/System/__HResults.cs @@ -44,6 +44,7 @@ namespace System internal const int COR_E_ARITHMETIC = unchecked((int)0x80070216); internal const int COR_E_ARRAYTYPEMISMATCH = unchecked((int)0x80131503); internal const int COR_E_BADIMAGEFORMAT = unchecked((int)0x8007000B); + internal const int COR_E_BADEXEFORMAT = unchecked((int)0x800700C1); internal const int COR_E_TYPEUNLOADED = unchecked((int)0x80131013); internal const int COR_E_CANNOTUNLOADAPPDOMAIN = unchecked((int)0x80131015); internal const int COR_E_COMEMULATE = unchecked((int)0x80131535); diff --git a/src/vm/clrex.cpp b/src/vm/clrex.cpp index 1c1501e..ba040b7 100644 --- a/src/vm/clrex.cpp +++ b/src/vm/clrex.cpp @@ -2002,18 +2002,7 @@ void DECLSPEC_NORETURN EEFileLoadException::Throw(LPCWSTR path, HRESULT hr, Exce if (hr == E_OUTOFMEMORY) COMPlusThrowOM(); -#ifndef CROSSGEN_COMPILE - // Remove path - location must be hidden for security purposes - - LPCWSTR pStart = wcsrchr(path, '\\'); - if (pStart != NULL) - pStart++; - else - pStart = path; -#else - LPCWSTR pStart = path; -#endif - EX_THROW_WITH_INNER(EEFileLoadException, (StackSString(pStart), hr), pInnerException); + EX_THROW_WITH_INNER(EEFileLoadException, (StackSString(path), hr), pInnerException); } /* static */ diff --git a/src/vm/peimage.cpp b/src/vm/peimage.cpp index 39b71ff..3367ef9 100644 --- a/src/vm/peimage.cpp +++ b/src/vm/peimage.cpp @@ -1189,7 +1189,13 @@ HANDLE PEImage::GetFileHandle() } if (m_hFile == INVALID_HANDLE_VALUE) + { +#if !defined(DACCESS_COMPILE) + EEFileLoadException::Throw(m_path, HRESULT_FROM_WIN32(GetLastError())); +#else // defined(DACCESS_COMPILE) ThrowLastError(); +#endif // !defined(DACCESS_COMPILE) + } return m_hFile; } diff --git a/src/vm/peimagelayout.cpp b/src/vm/peimagelayout.cpp index 2416681..34ba4d8 100644 --- a/src/vm/peimagelayout.cpp +++ b/src/vm/peimagelayout.cpp @@ -392,10 +392,21 @@ MappedImageLayout::MappedImageLayout(HANDLE hFile, PEImage* pOwner) { #ifndef CROSSGEN_COMPILE + // Capture last error as it may get reset below. + + DWORD dwLastError = GetLastError(); // There is no reflection-only load on CoreCLR and so we can always throw an error here. // It is important on Windows Phone. All assemblies that we load must have SEC_IMAGE set // so that the OS can perform signature verification. - ThrowLastError(); + if (pOwner->IsFile()) + { + EEFileLoadException::Throw(pOwner->GetPathForErrorMessages(), HRESULT_FROM_WIN32(dwLastError)); + } + else + { + // Throw generic exception. + ThrowWin32(dwLastError); + } #endif // CROSSGEN_COMPILE