Skip to content

Commit

Permalink
[mono] Fix passing of NULL via mono_runtime_invoke to method expectin…
Browse files Browse the repository at this point in the history
…g nullable (#79597)

The code was always trying to unbox the boxed vt, not accounting for NULL.
  • Loading branch information
BrzVlad authored Dec 13, 2022
1 parent 109c561 commit 4efdaf5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/mono/mono/metadata/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2470,9 +2470,14 @@ mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **
if (t->type == MONO_TYPE_GENERICINST && t->data.generic_class->container_class == mono_defaults.generic_nullable_class) {
MonoClass *klass = mono_class_from_mono_type_internal (t);
MonoObject *boxed_vt = (MonoObject*)params [i];
gpointer unboxed_vt = mono_object_unbox_internal (boxed_vt);
gpointer nullable_vt = g_alloca (mono_class_value_size (klass, NULL));

gpointer unboxed_vt;
if (boxed_vt)
unboxed_vt = mono_object_unbox_internal (boxed_vt);
else
unboxed_vt = NULL;

mono_nullable_init_unboxed (nullable_vt, unboxed_vt, klass);
if (!params_copy) {
params_copy = g_alloca (sig->param_count * sizeof (void*));
Expand Down

0 comments on commit 4efdaf5

Please sign in to comment.