-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mono] Fix crash when GetDelegateForFunctionPointer is passed non delegate type #79744
Conversation
…egate type When GetDelegateForFunctionPointer is invoked with non delegate type. It iterates over all the methods available to check if these methods are present. "Invoke" method is one such method which is executed by the coreCLR for any type of delegates. Having said that with non delegate "Invoke" method is not supported hence "mono_class_get_method_from_name_checked" returns NULL. Handle this case whenever mono_class_get_method_from_name_checked returns NULL for any methods which are not supported.
How can this happen ? Marshal.GetDelegateForFunctionPointer () checks that the type is a delegate type. |
This is specifically crashed when multicastDelegate type is passed to Marshal.GetDelegateForFunctionPointer(). |
@lambdageek , @thaystg Can you check the changes and review please. ? |
Could you please add/enable a test for this change? |
Apparently, passing MulticastDelegate is allowed according to this comment in Marshal.cs:
|
There is already an existing test case RunGetDelForFcnPtrTest available in file FunctionPointer.cs which tests this scenario as Marshal.GetDelegateForFunctionPointer(fcnptr, typeof(MulticastDelegate)). |
Hi, |
When GetDelegateForFunctionPointer is invoked with non-delegate type, it iterates over all the methods available to check if these methods are present. "Invoke" method is one such method which is executed by the coreCLR for any type of delegates. Having said that with non-delegate's "Invoke" method is not supported hence "mono_class_get_method_from_name_checked" returns NULL. Handle this case whenever mono_class_get_method_from_name_checked returns NULL for any methods which are not supported.