Merge pull request #4540 from kumpera/android-changes-part1
[mono.git] / mono / metadata / metadata-verify.c
index 65f3bba5686998a1b5b7ea59f79fd20ffbd4cf70..f31983c303f3a9b039fb44ba970437689a3a7114 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;
@@ -2396,7 +2398,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)
 {
@@ -2925,6 +2927,7 @@ verify_cattr_table (VerifyContext *ctx)
 static void
 verify_cattr_table_full (VerifyContext *ctx)
 {
+       MonoError error;
        MonoTableInfo *table = &ctx->image->tables [MONO_TABLE_CUSTOMATTRIBUTE];
        MonoMethod *ctor;
        const char *ptr;
@@ -2949,7 +2952,12 @@ verify_cattr_table_full (VerifyContext *ctx)
                        ADD_ERROR (ctx, g_strdup_printf ("Invalid CustomAttribute constructor row %d Token 0x%08x", i, data [MONO_CUSTOM_ATTR_TYPE]));
                }
 
-               ctor = mono_get_method (ctx->image, mtoken, NULL);
+               ctor = mono_get_method_checked (ctx->image, mtoken, NULL, NULL, &error);
+
+               if (!ctor) {
+                       ADD_ERROR (ctx, g_strdup_printf ("Invalid CustomAttribute content row %d Could not load ctor due to %s", i, mono_error_get_message (&error)));
+                       mono_error_cleanup (&error);
+               }
 
                /*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));
@@ -4048,7 +4056,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;
@@ -4221,8 +4229,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)
@@ -4240,7 +4246,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;
@@ -4283,7 +4289,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;
@@ -4366,7 +4372,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;
 }
 
@@ -4416,14 +4422,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;
 }