Skip to content

Commit

Permalink
Check for function pointers in SupportsSignature more thoroughly (dot…
Browse files Browse the repository at this point in the history
…net#525)

Repro case hit a pointer to a function pointer in a signature that this check wasn't covering. Reflection-invoking things that have function pointers in them is a TODO.
  • Loading branch information
MichalStrehovsky authored Jan 3, 2021
1 parent addcbc8 commit ea6eb00
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ private static TypeDesc UnwrapByRef(TypeDesc type)
return type;
}

private static bool ContainsFunctionPointer(TypeDesc type)
{
if (type.IsFunctionPointer)
return true;
else if (type.IsParameterizedType)
return ContainsFunctionPointer(((ParameterizedType)type).ParameterType);
else
return false;
}

public static bool SupportsSignature(MethodSignature signature)
{
// ----------------------------------------------------------------
Expand All @@ -57,15 +67,15 @@ public static bool SupportsSignature(MethodSignature signature)
// ----------------------------------------------------------------

TypeDesc unwrappedReturnType = UnwrapByRef(signature.ReturnType);
if (unwrappedReturnType.IsFunctionPointer)
if (ContainsFunctionPointer(unwrappedReturnType))
return false;
if (!unwrappedReturnType.IsSignatureVariable && unwrappedReturnType.IsByRefLike)
return false;

for (int i = 0; i < signature.Length; i++)
{
TypeDesc unwrappedParameterType = UnwrapByRef(signature[i]);
if (unwrappedParameterType.IsFunctionPointer)
if (ContainsFunctionPointer(unwrappedParameterType))
return false;
if (!unwrappedParameterType.IsSignatureVariable && unwrappedParameterType.IsByRefLike)
return false;
Expand Down

0 comments on commit ea6eb00

Please sign in to comment.