Throw if MethodDesc::GetName() returns null (#73760)
authorHyungju Lee <leee.lee@samsung.com>
Sun, 21 Aug 2022 06:52:55 +0000 (15:52 +0900)
committerGitHub <noreply@github.com>
Sun, 21 Aug 2022 06:52:55 +0000 (08:52 +0200)
src/coreclr/vm/memberload.cpp
src/coreclr/vm/method.cpp
src/coreclr/vm/method.hpp

index 5da50f2..cc8e369 100644 (file)
@@ -1132,7 +1132,7 @@ MemberLoader::FindMethod(
             ||
             (pCurDeclMD->MightHaveName(targetNameHash)
             // This is done last since it is the most expensive of the IF statement.
-            && StrCompFunc(pszName, pCurDeclMD->GetName()) == 0)
+            && StrCompFunc(pszName, pCurDeclMD->GetNameThrowing()) == 0)
            )
         {
             if (CompareMethodSigWithCorrectSubstitution(pSignature, cSignature, pModule, pCurDeclMD, pDefSubst, pMT))
index 9013d19..3e59b02 100644 (file)
@@ -218,7 +218,7 @@ BaseDomain *MethodDesc::GetDomain()
         FORBID_FAULT;
         SUPPORTS_DAC;
     }
-    CONTRACTL_END
+    CONTRACTL_END;
 
     return AppDomain::GetCurrentDomain();
 }
@@ -241,6 +241,24 @@ LoaderAllocator * MethodDesc::GetDomainSpecificLoaderAllocator()
 
 #endif //!DACCESS_COMPILE
 
+
+//*******************************************************************************
+LPCUTF8 MethodDesc::GetNameThrowing()
+{
+    CONTRACTL
+    {
+        THROWS;
+    }
+    CONTRACTL_END;
+
+    LPCUTF8 result = GetName();
+    if (result == NULL)
+    {
+        ThrowHR(COR_E_BADIMAGEFORMAT, BFA_METADATA_CORRUPT);
+    }
+    return result;
+}
+
 //*******************************************************************************
 LPCUTF8 MethodDesc::GetName(USHORT slot)
 {
@@ -260,7 +278,8 @@ LPCUTF8 MethodDesc::GetName()
         GC_NOTRIGGER;
         FORBID_FAULT;
         SUPPORTS_DAC;
-    }CONTRACTL_END;
+    }
+    CONTRACTL_END;
 
     if (IsArray())
     {
index 3103ea1..0532163 100644 (file)
@@ -323,6 +323,8 @@ public:
 
     LPCUTF8 GetName(USHORT slot);
 
+    LPCUTF8 GetNameThrowing();
+
     BOOL MightHaveName(ULONG nameHashValue);
 
     FORCEINLINE LPCUTF8 GetNameOnNonArrayClass()