From 3d23b944af69b9545ca6c09f5c0768e91aea2ac8 Mon Sep 17 00:00:00 2001 From: kumpera Date: Wed, 2 Jun 2010 14:34:09 +0000 Subject: [PATCH] 2010-06-02 Rodrigo Kumpera * verify.c (is_compatible_boxed_valuetype): Constaints must be recursively checked if one generic argument has a constraint on another. Fixes #610625. git-svn-id: svn+ssh://mono-cvs.ximian.com/source/trunk/mono@158341 e3ebcda4-bce8-0310-ba0a-eca2169e7518 --- mono/metadata/ChangeLog | 8 ++++++++ mono/metadata/verify.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/mono/metadata/ChangeLog b/mono/metadata/ChangeLog index 8026935b1..169039fa6 100644 --- a/mono/metadata/ChangeLog +++ b/mono/metadata/ChangeLog @@ -1,3 +1,11 @@ +2010-06-02 Rodrigo Kumpera + + * verify.c (is_compatible_boxed_valuetype): Constaints + must be recursively checked if one generic argument + has a constraint on another. + + Fixes #610625. + 2010-05-31 Miguel de Icaza * console-unix.c (terminal_get_dimensions): Fix my previous diff --git a/mono/metadata/verify.c b/mono/metadata/verify.c index 8392920f8..10a948f23 100644 --- a/mono/metadata/verify.c +++ b/mono/metadata/verify.c @@ -2156,6 +2156,30 @@ get_generic_param (VerifyContext *ctx, MonoType *param) return ctx->generic_context->method_inst->type_argv [param_num]->data.generic_param; } + +static gboolean +recursive_boxed_constraint_type_check (VerifyContext *ctx, MonoType *type, MonoClass *constraint_class, int recursion_level) +{ + MonoType *constraint_type = &constraint_class->byval_arg; + if (recursion_level <= 0) + return FALSE; + + if (verify_type_compatibility_full (ctx, type, mono_type_get_type_byval (constraint_type), FALSE)) + return TRUE; + + if (mono_type_is_generic_argument (constraint_type)) { + MonoGenericParam *param = get_generic_param (ctx, constraint_type); + MonoClass **class; + if (!param) + return FALSE; + for (class = mono_generic_param_info (param)->constraints; class && *class; ++class) { + if (recursive_boxed_constraint_type_check (ctx, type, *class, recursion_level - 1)) + return TRUE; + } + } + return FALSE; +} + /* * is_compatible_boxed_valuetype: * @@ -2178,8 +2202,12 @@ is_compatible_boxed_valuetype (VerifyContext *ctx, MonoType *type, MonoType *can if (mono_type_is_generic_argument (candidate)) { MonoGenericParam *param = get_generic_param (ctx, candidate); MonoClass **class; + if (!param) + return FALSE; + for (class = mono_generic_param_info (param)->constraints; class && *class; ++class) { - if (verify_type_compatibility_full (ctx, type, mono_type_get_type_byval (& (*class)->byval_arg), FALSE)) + /*256 should be enough since there can't be more than 255 generic arguments.*/ + if (recursive_boxed_constraint_type_check (ctx, type, *class, 256)) return TRUE; } } -- 2.11.4.GIT