Author: kumpera
Date: 2007-12-05 17:21:58 -0500 (Wed, 05 Dec 2007)
New Revision: 90781

Modified:
   trunk/mono/mono/metadata/ChangeLog
   trunk/mono/mono/metadata/verify.c
Log:
2007-12-05  Rodrigo Kumpera  <[EMAIL PROTECTED]>

        * verify.c (mono_method_verify): null literal requires special handling,
        the value pushed on stack need to be flagged as so.

        * verify.c (do_ldelema): Verify ldelema properly.



Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog  2007-12-05 22:07:09 UTC (rev 90780)
+++ trunk/mono/mono/metadata/ChangeLog  2007-12-05 22:21:58 UTC (rev 90781)
@@ -1,5 +1,12 @@
 2007-12-05  Rodrigo Kumpera  <[EMAIL PROTECTED]>
 
+       * verify.c (mono_method_verify): null literal requires special handling,
+       the value pushed on stack need to be flagged as so.
+
+       * verify.c (do_ldelema): Verify ldelema properly.
+
+2007-12-05  Rodrigo Kumpera  <[EMAIL PROTECTED]>
+
        * verify.c: Verify ldlen properly.
 
 2007-12-05  Zoltan Varga  <[EMAIL PROTECTED]>

Modified: trunk/mono/mono/metadata/verify.c
===================================================================
--- trunk/mono/mono/metadata/verify.c   2007-12-05 22:07:09 UTC (rev 90780)
+++ trunk/mono/mono/metadata/verify.c   2007-12-05 22:21:58 UTC (rev 90781)
@@ -57,6 +57,7 @@
 
 #define UNMASK_TYPE(type) ((type) & TYPE_MASK)
 #define IS_MANAGED_POINTER(type) (((type) & POINTER_MASK) == POINTER_MASK)
+#define IS_NULL_LITERAL(type) (((type) & NULL_LITERAL_MASK) == 
NULL_LITERAL_MASK)
 
 enum {
        IL_CODE_FLAG_NOT_PROCESSED  = 0,
@@ -130,6 +131,9 @@
 
        /* Controlled Mutability Manager Pointer */
        CMMP_MASK = 0x200,
+
+       /* The stack type is a null literal*/
+       NULL_LITERAL_MASK = 0x400,
 };
 
 static const char* const
@@ -2833,6 +2837,7 @@
        set_stack_value (stack_push (ctx), mono_class_get_type 
(mono_array_class_get (mono_class_from_mono_type (type), 1)), FALSE);
 }
 
+/*FIXME handle arrays that are not 0-indexed*/
 static void
 do_ldlen (VerifyContext *ctx)
 {
@@ -2849,6 +2854,42 @@
        stack_push_val (ctx, TYPE_NATIVE_INT, 
&mono_defaults.int_class->byval_arg);     
 }
 
+/*FIXME handle arrays that are not 0-indexed*/
+/*FIXME handle readonly prefix and CMMP*/
+static void
+do_ldelema (VerifyContext *ctx, int klass_token)
+{
+       ILStackDesc *index, *array;
+       MonoType *type = get_boxable_mono_type (ctx, klass_token);
+       gboolean valid; 
+
+       if (!type)
+               return;
+
+       if (!check_underflow (ctx, 2))
+               return;
+
+       index = stack_pop (ctx);
+       array = stack_pop (ctx);
+
+       if (index->stype != TYPE_I4 && index->stype != TYPE_NATIVE_INT)
+               CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Index type(%s) for 
ldelema is not an int or a native int at 0x%04x", type_names [UNMASK_TYPE 
(index->stype)], ctx->ip_offset));
+
+       if (!IS_NULL_LITERAL (array->stype)) {
+               if (array->stype != TYPE_COMPLEX || array->type->type != 
MONO_TYPE_SZARRAY)
+                       CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Invalid 
array type(%s) for ldlen at 0x%04x", type_names [UNMASK_TYPE (array->stype)], 
ctx->ip_offset));
+       
+               if (get_stack_type (type) == TYPE_I4 || get_stack_type (type) 
== TYPE_NATIVE_INT)
+                       valid = verify_type_compatibility_full (ctx, type, 
&array->type->data.klass->byval_arg, TRUE);
+               else
+                       valid = mono_metadata_type_equal (type, 
&array->type->data.klass->byval_arg);
+               if (!valid)
+                       CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Invalid 
array type on stack for ldelema at 0x%04x", ctx->ip_offset));
+       }
+
+       set_stack_value (stack_push (ctx), type, TRUE); 
+}
+
 /*Merge the stacks and perform compat checks*/
 static void
 merge_stacks (VerifyContext *ctx, ILCodeDesc *from, ILCodeDesc *to, int start) 
@@ -3150,7 +3191,7 @@
 
                case CEE_LDNULL:
                        if (check_overflow (&ctx))
-                               stack_push_val (&ctx,TYPE_COMPLEX, 
&mono_defaults.object_class->byval_arg);
+                               stack_push_val (&ctx, TYPE_COMPLEX | 
NULL_LITERAL_MASK, &mono_defaults.object_class->byval_arg);
                        ++ip;
                        break;
 
@@ -3468,17 +3509,10 @@
                        break;
 
                case CEE_LDELEMA:
-                       if (check_underflow (&ctx, 2))
-                               break;
-                       --ctx.eval.size;
-                       if (stack_top (&ctx)->stype != TYPE_COMPLEX)
-                               ADD_VERIFY_ERROR (&ctx, g_strdup_printf 
("Invalid array argument to ldelema at 0x%04x", ip_offset));
-                       if (stack_top (&ctx)->stype != TYPE_I4 && stack_top 
(&ctx)->stype != TYPE_PTR)
-                               ADD_VERIFY_ERROR (&ctx, g_strdup_printf ("Array 
index needs to be Int32 or IntPtr at 0x%04x", ip_offset));
-                       stack_top (&ctx)->stype = TYPE_COMPLEX;
-                       token = read32 (ip + 1);
+                       do_ldelema (&ctx, read32 (ip + 1));
                        ip += 5;
                        break;
+
                case CEE_LDELEM_I1:
                case CEE_LDELEM_U1:
                case CEE_LDELEM_I2:

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to