Skip to content

Commit 4efdaf5

Browse files
authored
[mono] Fix passing of NULL via mono_runtime_invoke to method expecting nullable (#79597)
The code was always trying to unbox the boxed vt, not accounting for NULL.
1 parent 109c561 commit 4efdaf5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/mono/mono/metadata/object.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2470,9 +2470,14 @@ mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **
24702470
if (t->type == MONO_TYPE_GENERICINST && t->data.generic_class->container_class == mono_defaults.generic_nullable_class) {
24712471
MonoClass *klass = mono_class_from_mono_type_internal (t);
24722472
MonoObject *boxed_vt = (MonoObject*)params [i];
2473-
gpointer unboxed_vt = mono_object_unbox_internal (boxed_vt);
24742473
gpointer nullable_vt = g_alloca (mono_class_value_size (klass, NULL));
24752474

2475+
gpointer unboxed_vt;
2476+
if (boxed_vt)
2477+
unboxed_vt = mono_object_unbox_internal (boxed_vt);
2478+
else
2479+
unboxed_vt = NULL;
2480+
24762481
mono_nullable_init_unboxed (nullable_vt, unboxed_vt, klass);
24772482
if (!params_copy) {
24782483
params_copy = g_alloca (sig->param_count * sizeof (void*));

0 commit comments

Comments
 (0)