Skip to content
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

Debugger: Prevent Abort on Invalid Virtual Method #2115

Open
wants to merge 1 commit into
base: unity-main
Choose a base branch
from

Conversation

scott-ferguson-unity
Copy link
Collaborator

If the debugger is asked to invoke an interface or virtual method on a class the mono_object_get_virtual_method_internal will assert & abort (or crash).

mono_object_get_virtual_method_internal assumes that it is being asked to invoke a virtual method on an instance that implements it. If that's not true it will assert & abort or access invalid memory if assertions are disabled.

To protect against this we check if the this_arg can be cast to the interface or base class type. If it can then we should be safe to call mono_object_get_virtual_method_internal.

  • Should this pull request have release notes?
    • Yes
    • No
  • Do these changes need to be back ported?
    • Yes
    • No
  • Do these changes need to be upstreamed to mono/mono or dotnet/runtime repositories?
    • Yes
    • No

Reviewers: please consider these questions as well! ❤️

Release notes

Fixed UUM-97917 @scott-ferguson-unity
Mono: Prevent debugger crash when watching or evaluating an interface property or method without an instance (i.e. nameof(IInterface.Property).

If the debugger is asked to invoke an interface or virtual
method on a class the mono_object_get_virtual_method_internal
will assert & abort (or crash).

mono_object_get_virtual_method_internal assumes that
it is being asked to invoke a virtual method on an instance
that implements it.  If that's not true it will assert & abort or
access invalid memory if assertions are disabled.

To protect against this we check if the this_arg can be cast to
the interface or base class type.  If it can then we should be
safe to call mono_object_get_virtual_method_internal.
@UnityAlex
Copy link
Collaborator

Were you able to reproduce this issue with the upstream mono in dotnet/runtime? It doesn't look like this change is there so it might be worthwhile upstreaming the change unless they've fixed it in some other way.

@@ -6545,6 +6545,10 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8
PRINT_DEBUG_MSG (1, "[%p] Error: Interface method invoked without this argument.\n", (gpointer) (gsize) mono_native_thread_id_get ());
return ERR_INVALID_ARGUMENT;
}
if (!mono_object_isinst(this_arg, m->klass)) {
PRINT_DEBUG_MSG (1, "[%p] Error: Interface method invoked on object that doesn't implement the interface.\n", (gpointer) (gsize) mono_native_thread_id_get ());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, should the message include more info like type and interface/and method name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants