[verifier] Handle csc encoding of enums in cattr blobs. Fixes #58168.
[mono.git] / mono / metadata / metadata-verify.c
index 753e5269e921bdb9dec91aa0fdac4faf9f4f817b..f0299605583b7a7686f78031422521334b25ee4f 100644 (file)
@@ -1,10 +1,12 @@
-/*
- * metadata-verify.c: Metadata verfication support
+/**
+ * \file
+ * Metadata verfication support
  *
  * Author:
  *     Mono Project (http://www.mono-project.com)
  *
  * Copyright (C) 2005-2008 Novell, Inc. (http://www.novell.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 #include <mono/metadata/object-internals.h>
 #include <mono/metadata/verify.h>
@@ -729,7 +731,7 @@ verify_cli_header (VerifyContext *ctx)
        if (!read32 (ptr + 8) || !read32 (ptr + 12))
                ADD_ERROR (ctx, g_strdup_printf ("Missing medatata section in the CLI header"));
 
-       if ((read32 (ptr + 16) & ~0x0001000B) != 0)
+       if ((read32 (ptr + 16) & ~0x0003000B) != 0)
                ADD_ERROR (ctx, g_strdup_printf ("Invalid CLI header flags"));
 
        ptr += 24;
@@ -1892,8 +1894,13 @@ handle_enum:
                FAIL (ctx, g_strdup_printf ("CustomAttribute: Invalid boxed object type %x", sub_type));
        }
 
-
        case MONO_TYPE_CLASS:
+               if (klass && klass->enumtype) {
+                       klass = klass->element_class;
+                       type = klass->byval_arg.type;
+                       goto handle_enum;
+               }
+
                if (klass != mono_defaults.systemtype_class)
                        FAIL (ctx, g_strdup_printf ("CustomAttribute: Invalid class parameter type %s:%s ",klass->name_space, klass->name));
                *_ptr = ptr;
@@ -2396,7 +2403,7 @@ verify_typeref_table (VerifyContext *ctx)
 }
 
 /*bits 9,11,14,15,19,21,24-31 */
-#define INVALID_TYPEDEF_FLAG_BITS ((1 << 6) | (1 << 9) | (1 << 14) | (1 << 15) | (1 << 19) | (1 << 21) | 0xFF000000)
+#define INVALID_TYPEDEF_FLAG_BITS ((1 << 6) | (1 << 9) | (1 << 15) | (1 << 19) | (1 << 21) | 0xFF000000)
 static void
 verify_typedef_table (VerifyContext *ctx)
 {
@@ -2411,7 +2418,7 @@ verify_typedef_table (VerifyContext *ctx)
        for (i = 0; i < table->rows; ++i) {
                mono_metadata_decode_row (table, i, data, MONO_TYPEDEF_SIZE);
                if (data [MONO_TYPEDEF_FLAGS] & INVALID_TYPEDEF_FLAG_BITS)
-                       ADD_ERROR (ctx, g_strdup_printf ("Invalid typedef row %d invalid flags field 0x%08x", i, data [MONO_TYPEDEF_FLAGS]));
+                       ADD_ERROR (ctx, g_strdup_printf ("Invalid typedef row %d invalid flags field 0x%08x rejected bits: 0x%08x", i, data [MONO_TYPEDEF_FLAGS], data [MONO_TYPEDEF_FLAGS] & INVALID_TYPEDEF_FLAG_BITS));
 
                if ((data [MONO_TYPEDEF_FLAGS] & TYPE_ATTRIBUTE_LAYOUT_MASK) == 0x18)
                        ADD_ERROR (ctx, g_strdup_printf ("Invalid typedef row %d invalid class layout 0x18", i));
@@ -2960,8 +2967,11 @@ verify_cattr_table_full (VerifyContext *ctx)
                /*This can't fail since this is checked in is_valid_cattr_blob*/
                g_assert (decode_signature_header (ctx, data [MONO_CUSTOM_ATTR_VALUE], &size, &ptr));
 
-               if (!is_valid_cattr_content (ctx, ctor, ptr, size))
-                       ADD_ERROR (ctx, g_strdup_printf ("Invalid CustomAttribute content row %d Value field 0x%08x", i, data [MONO_CUSTOM_ATTR_VALUE]));
+               if (!is_valid_cattr_content (ctx, ctor, ptr, size)) {
+                       char *ctor_name =  mono_method_full_name (ctor, TRUE);
+                       ADD_ERROR (ctx, g_strdup_printf ("Invalid CustomAttribute content row %d Value field 0x%08x ctor: %s", i, data [MONO_CUSTOM_ATTR_VALUE], ctor_name));
+                       g_free (ctor_name);
+               }
        }
 }
 
@@ -4054,7 +4064,7 @@ mono_verifier_verify_method_signature (MonoImage *image, guint32 offset, MonoErr
 {
        VerifyContext ctx;
 
-       mono_error_init (error);
+       error_init (error);
 
        if (!mono_verifier_is_enabled_for_image (image))
                return TRUE;
@@ -4227,8 +4237,6 @@ mono_verifier_is_sig_compatible (MonoImage *image, MonoMethod *method, MonoMetho
                        return FALSE;
                if (original_sig->explicit_this != signature->explicit_this)
                        return FALSE;
-               if (original_sig->call_convention != signature->call_convention)
-                       return FALSE;
                if (original_sig->pinvoke != signature->pinvoke)
                        return FALSE;
                if (original_sig->sentinelpos != signature->sentinelpos)
@@ -4246,7 +4254,7 @@ mono_verifier_verify_typeref_row (MonoImage *image, guint32 row, MonoError *erro
        MonoTableInfo *table = &image->tables [MONO_TABLE_TYPEREF];
        guint32 data [MONO_TYPEREF_SIZE];
 
-       mono_error_init (error);
+       error_init (error);
 
        if (!mono_verifier_is_enabled_for_image (image))
                return TRUE;
@@ -4289,7 +4297,7 @@ mono_verifier_verify_methodimpl_row (MonoImage *image, guint32 row, MonoError *e
        MonoTableInfo *table = &image->tables [MONO_TABLE_METHODIMPL];
        guint32 data [MONO_METHODIMPL_SIZE];
 
-       mono_error_init (error);
+       error_init (error);
 
        if (!mono_verifier_is_enabled_for_image (image))
                return TRUE;
@@ -4372,7 +4380,7 @@ mono_verifier_verify_method_header (MonoImage *image, guint32 offset, GSList **e
 gboolean
 mono_verifier_verify_method_signature (MonoImage *image, guint32 offset, MonoError *error)
 {
-       mono_error_init (error);
+       error_init (error);
        return TRUE;
 }
 
@@ -4422,14 +4430,14 @@ mono_verifier_is_sig_compatible (MonoImage *image, MonoMethod *method, MonoMetho
 gboolean
 mono_verifier_verify_typeref_row (MonoImage *image, guint32 row, MonoError *error)
 {
-       mono_error_init (error);
+       error_init (error);
        return TRUE;
 }
 
 gboolean
 mono_verifier_verify_methodimpl_row (MonoImage *image, guint32 row, MonoError *error)
 {
-       mono_error_init (error);
+       error_init (error);
        return TRUE;
 }