Skip to content

Commit 44f84eb

Browse files
committed
Do not ignore ClassLoader::ResolveTokenToTypeDefThrowing return values
ResolveTokenToTypeDefThrowing can return FALSE in some situations when the token cannot be resolved. The calling code has to deal with the situation gracefully since the [out] arguments are not initialized in that case. Related to #121791
1 parent 5735338 commit 44f84eb

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/coreclr/vm/method.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,10 +2315,12 @@ bool IsTypeDefOrRefImplementedInSystemModule(Module* pModule, mdToken tk)
23152315
mdToken tkTypeDef;
23162316
Module* pModuleOfTypeDef;
23172317

2318-
ClassLoader::ResolveTokenToTypeDefThrowing(pModule, tk, &pModuleOfTypeDef, &tkTypeDef);
2319-
if (pModuleOfTypeDef->IsSystem())
2318+
if (ClassLoader::ResolveTokenToTypeDefThrowing(pModule, tk, &pModuleOfTypeDef, &tkTypeDef))
23202319
{
2321-
return true;
2320+
if (pModuleOfTypeDef->IsSystem())
2321+
{
2322+
return true;
2323+
}
23222324
}
23232325
}
23242326

src/coreclr/vm/methodtablebuilder.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3872,7 +3872,11 @@ CorElementType MethodTableBuilder::GetCorElementTypeOfTypeDefOrRefForStaticField
38723872
Module *pModuleOfTypeDef;
38733873
mdTypeDef tkTypeDef;
38743874

3875-
ClassLoader::ResolveTokenToTypeDefThrowing(module, typeDefOrRef, &pModuleOfTypeDef, &tkTypeDef);
3875+
if (!ClassLoader::ResolveTokenToTypeDefThrowing(module, typeDefOrRef, &pModuleOfTypeDef, &tkTypeDef))
3876+
{
3877+
// This will be fully resolved and exception thrown later.
3878+
return ELEMENT_TYPE_VALUETYPE;
3879+
}
38763880

38773881
// First check to see if the type is byref-like
38783882
if (pModuleOfTypeDef->GetCustomAttribute(tkTypeDef,
@@ -3907,11 +3911,12 @@ CorElementType MethodTableBuilder::GetCorElementTypeOfTypeDefOrRefForStaticField
39073911
Module *pModuleOfSystemEnumType;
39083912
mdTypeDef tkTypeDefOfSystemEnumType;
39093913

3910-
ClassLoader::ResolveTokenToTypeDefThrowing(pModuleOfTypeDef, tkTypeDefExtends, &pModuleOfSystemEnumType, &tkTypeDefOfSystemEnumType);
3911-
3912-
if (pModuleOfSystemEnumType != NULL && pModuleOfSystemEnumType->IsSystem())
3914+
if (ClassLoader::ResolveTokenToTypeDefThrowing(pModuleOfTypeDef, tkTypeDefExtends, &pModuleOfSystemEnumType, &tkTypeDefOfSystemEnumType))
39133915
{
3914-
thisIsAnEnum = true;
3916+
if (pModuleOfSystemEnumType != NULL && pModuleOfSystemEnumType->IsSystem())
3917+
{
3918+
thisIsAnEnum = true;
3919+
}
39153920
}
39163921
}
39173922
}

0 commit comments

Comments
 (0)