[xbuild] Use the env var $MSBuildExtensionsPath before trying other paths.
[mono.git] / mono / metadata / metadata-verify.c
index 406c5166f12af0c4117a5bf9be32e4797d431ccd..d8e002d6906c176b59b789b143f8c755c77c8189 100644 (file)
@@ -1230,7 +1230,7 @@ parse_custom_mods (VerifyContext *ctx, const char **_ptr, const char *end)
                if (!safe_read_cint (token, ptr, end))
                        FAIL (ctx, g_strdup ("CustomMod: Not enough room for the token"));
        
-               if (!is_valid_coded_index (ctx, TYPEDEF_OR_REF_DESC, token))
+               if (!is_valid_coded_index (ctx, TYPEDEF_OR_REF_DESC, token) || !get_coded_index_token (TYPEDEF_OR_REF_DESC, token))
                        FAIL (ctx, g_strdup_printf ("CustomMod: invalid TypeDefOrRef token %x", token));
        }
 
@@ -1287,7 +1287,7 @@ parse_generic_inst (VerifyContext *ctx, const char **_ptr, const char *end)
        if (!safe_read_cint (token, ptr, end))
                FAIL (ctx, g_strdup ("GenericInst: Not enough room for type token"));
 
-       if (!is_valid_coded_index (ctx, TYPEDEF_OR_REF_DESC, token))
+       if (!is_valid_coded_index (ctx, TYPEDEF_OR_REF_DESC, token) || !get_coded_index_token (TYPEDEF_OR_REF_DESC, token))
                FAIL (ctx, g_strdup_printf ("GenericInst: invalid TypeDefOrRef token %x", token));
 
        if (ctx->token) {
@@ -1349,7 +1349,7 @@ parse_type (VerifyContext *ctx, const char **_ptr, const char *end)
                if (!safe_read_cint (token, ptr, end))
                        FAIL (ctx, g_strdup ("Type: Not enough room for the type token"));
        
-               if (!is_valid_coded_index (ctx, TYPEDEF_OR_REF_DESC, token))
+               if (!is_valid_coded_index (ctx, TYPEDEF_OR_REF_DESC, token) || !get_coded_index_token (TYPEDEF_OR_REF_DESC, token))
                        FAIL (ctx, g_strdup_printf ("Type: invalid TypeDefOrRef token %x", token));
 
                if (!get_coded_index_token (TYPEDEF_OR_REF_DESC, token))
@@ -1652,6 +1652,20 @@ is_valid_method_signature (VerifyContext *ctx, guint32 offset)
        return parse_method_signature (ctx, &ptr, end, FALSE, FALSE);
 }
 
+static gboolean
+is_valid_memberref_method_signature (VerifyContext *ctx, guint32 offset)
+{
+       guint32 size = 0;
+       const char *ptr = NULL, *end;
+
+       if (!decode_signature_header (ctx, offset, &size, &ptr))
+               FAIL (ctx, g_strdup ("MemberRefSig: Could not decode signature header"));
+       end = ptr + size;
+
+       return parse_method_signature (ctx, &ptr, end, TRUE, FALSE);
+}
+
+
 static gboolean
 is_valid_method_or_field_signature (VerifyContext *ctx, guint32 offset)
 {
@@ -2420,6 +2434,9 @@ verify_typedef_table (VerifyContext *ctx)
                if (data [MONO_TYPEDEF_EXTENDS] && !is_valid_coded_index (ctx, TYPEDEF_OR_REF_DESC, data [MONO_TYPEDEF_EXTENDS]))
                        ADD_ERROR (ctx, g_strdup_printf ("Invalid typedef row %d extend field coded index 0x%08x", i, data [MONO_TYPEDEF_EXTENDS]));
 
+               if (data [MONO_TYPEDEF_EXTENDS] && !get_coded_index_token (TYPEDEF_OR_REF_DESC, data [MONO_TYPEDEF_EXTENDS]))
+                       ADD_ERROR (ctx, g_strdup_printf ("Invalid typedef row %d zero coded extend field coded index 0x%08x", i, data [MONO_TYPEDEF_EXTENDS]));
+
                visibility = data [MONO_TYPEDEF_FLAGS] & TYPE_ATTRIBUTE_VISIBILITY_MASK;
                if ((visibility >= TYPE_ATTRIBUTE_NESTED_PUBLIC && visibility <= TYPE_ATTRIBUTE_NESTED_FAM_OR_ASSEM) &&
                        search_sorted_table (ctx, MONO_TABLE_NESTEDCLASS, MONO_NESTED_CLASS_NESTED, i + 1) == -1)
@@ -3352,7 +3369,7 @@ verify_fieldrva_table (VerifyContext *ctx)
        }
 }
 
-#define INVALID_ASSEMBLY_FLAGS_BITS ~((1 << 0) | (1 << 4) | (1 << 8) | (1 << 14) | (1 << 15))
+#define INVALID_ASSEMBLY_FLAGS_BITS ~((1 << 0) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8) | (1 << 14) | (1 << 15))
 static void
 verify_assembly_table (VerifyContext *ctx)
 {
@@ -4033,7 +4050,7 @@ mono_verifier_verify_method_signature (MonoImage *image, guint32 offset, MonoErr
 }
 
 gboolean
-mono_verifier_verify_memberref_signature (MonoImage *image, guint32 offset, GSList **error_list)
+mono_verifier_verify_memberref_method_signature (MonoImage *image, guint32 offset, GSList **error_list)
 {
        VerifyContext ctx;
 
@@ -4043,7 +4060,22 @@ mono_verifier_verify_memberref_signature (MonoImage *image, guint32 offset, GSLi
        init_verify_context (&ctx, image, error_list != NULL);
        ctx.stage = STAGE_TABLES;
 
-       is_valid_method_or_field_signature (&ctx, offset);
+       is_valid_memberref_method_signature (&ctx, offset);
+       return cleanup_context (&ctx, error_list);
+}
+
+gboolean
+mono_verifier_verify_memberref_field_signature (MonoImage *image, guint32 offset, GSList **error_list)
+{
+       VerifyContext ctx;
+
+       if (!mono_verifier_is_enabled_for_image (image))
+               return TRUE;
+
+       init_verify_context (&ctx, image, error_list != NULL);
+       ctx.stage = STAGE_TABLES;
+
+       is_valid_field_signature (&ctx, offset);
        return cleanup_context (&ctx, error_list);
 }
 
@@ -4252,14 +4284,14 @@ mono_verifier_verify_methodimpl_row (MonoImage *image, guint32 row, MonoError *e
        mono_metadata_decode_row (table, row, data, MONO_METHODIMPL_SIZE);
 
        body = method_from_method_def_or_ref (image, data [MONO_METHODIMPL_BODY], NULL);
-       if (mono_loader_get_last_error ()) {
+       if (!body || mono_loader_get_last_error ()) {
                mono_loader_clear_error ();
                mono_error_set_bad_image (error, image, "Invalid methodimpl body for row %x", row);
                return FALSE;
        }
 
        declaration = method_from_method_def_or_ref (image, data [MONO_METHODIMPL_DECLARATION], NULL);
-       if (mono_loader_get_last_error ()) {
+       if (!declaration || mono_loader_get_last_error ()) {
                mono_loader_clear_error ();
                mono_error_set_bad_image (error, image, "Invalid methodimpl declaration for row %x", row);
                return FALSE;
@@ -4332,12 +4364,6 @@ mono_verifier_verify_method_signature (MonoImage *image, guint32 offset, MonoErr
        return TRUE;
 }
 
-gboolean
-mono_verifier_verify_memberref_signature (MonoImage *image, guint32 offset, GSList **error_list)
-{
-       return TRUE;
-}
-
 gboolean
 mono_verifier_verify_standalone_signature (MonoImage *image, guint32 offset, GSList **error_list)
 {
@@ -4395,4 +4421,16 @@ mono_verifier_verify_methodimpl_row (MonoImage *image, guint32 row, MonoError *e
        return TRUE;
 }
 
+gboolean
+mono_verifier_verify_memberref_method_signature (MonoImage *image, guint32 offset, GSList **error_list)
+{
+       return TRUE;
+}
+
+gboolean
+mono_verifier_verify_memberref_field_signature (MonoImage *image, guint32 offset, GSList **error_list)
+{
+       return TRUE;
+}
+
 #endif /* DISABLE_VERIFIER */