* 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>
return FALSE;
if (ctx->stage > STAGE_PE) {
- MonoCLIImageInfo *iinfo = ctx->image->image_info;
+ MonoCLIImageInfo *iinfo = (MonoCLIImageInfo *)ctx->image->image_info;
const int top = iinfo->cli_section_count;
MonoSectionTable *tables = iinfo->cli_section_tables;
int i;
DataDirectory it = ctx->data_directories [RESOURCE_TABLE_IDX];
guint32 offset;
guint16 named_entries, id_entries;
- const char *ptr, *root, *end;
+ const char *ptr;
if (it.rva == 0)
return;
ADD_ERROR (ctx, g_strdup_printf ("Resource section is too small, must be at least 16 bytes long but it's %d long", it.size));
offset = it.translated_offset;
- root = ptr = ctx->data + offset;
- end = root + it.size;
+ ptr = ctx->data + offset;
g_assert (offset != INVALID_OFFSET);
static DataDirectory
get_data_dir (VerifyContext *ctx, int idx)
{
- MonoCLIImageInfo *iinfo = ctx->image->image_info;
+ MonoCLIImageInfo *iinfo = (MonoCLIImageInfo *)ctx->image->image_info;
MonoPEDirEntry *entry= &iinfo->cli_header.datadir.pe_export_table;
DataDirectory res;
base = tinfo->base;
VERIFIER_DEBUG ( printf ("looking token %x table %d col %d rsize %d roff %d\n", coded_token, table, column, locator.col_size, locator.col_offset) );
- res = mono_binary_search (&locator, base, tinfo->rows, tinfo->row_size, token_locator);
+ res = (const char *)mono_binary_search (&locator, base, tinfo->rows, tinfo->row_size, token_locator);
if (!res)
return -1;
return NULL;
}
- enum_name = g_memdup (str_start, str_len + 1);
+ enum_name = (char *)g_memdup (str_start, str_len + 1);
enum_name [str_len] = 0;
type = mono_reflection_type_from_name (enum_name, ctx->image);
if (!type) {
} else if (etype == 0x50 || etype == MONO_TYPE_CLASS) {
klass = mono_defaults.systemtype_class;
} else if ((etype >= MONO_TYPE_BOOLEAN && etype <= MONO_TYPE_STRING) || etype == 0x51) {
- simple_type.type = etype == 0x51 ? MONO_TYPE_OBJECT : etype;
+ simple_type.type = etype == 0x51 ? MONO_TYPE_OBJECT : (MonoTypeEnum)etype;
klass = mono_class_from_mono_type (&simple_type);
} else
FAIL (ctx, g_strdup_printf ("CustomAttribute: Invalid array element type %x", etype));
FAIL (ctx, g_strdup_printf ("CustomAttribute: Not enough space for named parameter %d type", i));
if (kind >= MONO_TYPE_BOOLEAN && kind <= MONO_TYPE_STRING) {
- simple_type.type = kind;
+ simple_type.type = (MonoTypeEnum)kind;
type = &simple_type;
} else if (kind == MONO_TYPE_ENUM) {
MonoClass *klass = get_enum_by_encoded_name (ctx, &ptr, end);
} else if (etype == 0x50 || etype == MONO_TYPE_CLASS) {
klass = mono_defaults.systemtype_class;
} else if ((etype >= MONO_TYPE_BOOLEAN && etype <= MONO_TYPE_STRING) || etype == 0x51) {
- simple_type.type = etype == 0x51 ? MONO_TYPE_OBJECT : etype;
+ simple_type.type = etype == 0x51 ? MONO_TYPE_OBJECT : (MonoTypeEnum)etype;
klass = mono_class_from_mono_type (&simple_type);
} else
FAIL (ctx, g_strdup_printf ("CustomAttribute: Invalid array element type %x", etype));
static void
verify_cattr_table_full (VerifyContext *ctx)
{
+ MonoError error;
MonoTableInfo *table = &ctx->image->tables [MONO_TABLE_CUSTOMATTRIBUTE];
MonoMethod *ctor;
const char *ptr;
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));
if (!found_add)
ADD_ERROR (ctx, g_strdup_printf ("Invalid Event row %d has no AddOn associated method", i));
if (!found_remove)
- ADD_ERROR (ctx, g_strdup_printf ("Invalid Event row %d has no AddOn associated method", i));
+ ADD_ERROR (ctx, g_strdup_printf ("Invalid Event row %d has no RemoveOn associated method", i));
}
}
static void
verify_manifest_resource_table (VerifyContext *ctx)
{
- MonoCLIImageInfo *iinfo = ctx->image->image_info;
+ MonoCLIImageInfo *iinfo = (MonoCLIImageInfo *)ctx->image->image_info;
MonoCLIHeader *ch = &iinfo->cli_cli_header;
MonoTableInfo *table = &ctx->image->tables [MONO_TABLE_MANIFESTRESOURCE];
guint32 data [MONO_MANIFEST_SIZE], impl_table, token, resources_size;
MonoTableInfo *table = &ctx->image->tables [MONO_TABLE_GENERICPARAMCONSTRAINT];
guint32 data [MONO_GENPARCONSTRAINT_SIZE];
int i;
+ guint32 last_owner = 0, last_constraint = 0;
for (i = 0; i < table->rows; ++i) {
mono_metadata_decode_row (table, i, data, MONO_GENPARCONSTRAINT_SIZE);
if (!get_coded_index_token (TYPEDEF_OR_REF_DESC, data [MONO_GENPARCONSTRAINT_CONSTRAINT]))
ADD_ERROR (ctx, g_strdup_printf ("GenericParamConstraint table row %d has null Constraint token", i));
+
+ if (last_owner > data [MONO_GENPARCONSTRAINT_GENERICPAR])
+ ADD_ERROR (ctx, g_strdup_printf ("GenericParamConstraint table row %d is not properly sorted. Previous value of the owner column is 0x%08x current value is 0x%08x", i, last_owner, data [MONO_GENPARCONSTRAINT_GENERICPAR]));
+
+ if (last_owner == data [MONO_GENPARCONSTRAINT_GENERICPAR]) {
+ if (last_constraint == data [MONO_GENPARCONSTRAINT_CONSTRAINT])
+ ADD_ERROR (ctx, g_strdup_printf ("GenericParamConstraint table row %d has duplicate constraint 0x%08x", i, last_constraint));
+ } else {
+ last_owner = data [MONO_GENPARCONSTRAINT_GENERICPAR];
+ }
+ last_constraint = data [MONO_GENPARCONSTRAINT_CONSTRAINT];
}
}
static guint
typedef_hash (gconstpointer _key)
{
- const TypeDefUniqueId *key = _key;
+ const TypeDefUniqueId *key = (const TypeDefUniqueId *)_key;
return g_str_hash (key->name) ^ g_str_hash (key->name_space) ^ key->resolution_scope; /*XXX better salt the int key*/
}
static gboolean
typedef_equals (gconstpointer _a, gconstpointer _b)
{
- const TypeDefUniqueId *a = _a;
- const TypeDefUniqueId *b = _b;
+ const TypeDefUniqueId *a = (const TypeDefUniqueId *)_a;
+ const TypeDefUniqueId *b = (const TypeDefUniqueId *)_b;
return !strcmp (a->name, b->name) && !strcmp (a->name_space, b->name_space) && a->resolution_scope == b->resolution_scope;
}
{
g_free (ctx->sections);
if (ctx->errors) {
- MonoVerifyInfo *info = ctx->errors->data;
+ MonoVerifyInfo *info = (MonoVerifyInfo *)ctx->errors->data;
mono_error_set_bad_image (error, ctx->image, "%s", info->message);
mono_free_verify_list (ctx->errors);
}
mono_metadata_decode_row (table, row, data, MONO_METHODIMPL_SIZE);
- body = method_from_method_def_or_ref (image, data [MONO_METHODIMPL_BODY], NULL);
- 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);
+ body = method_from_method_def_or_ref (image, data [MONO_METHODIMPL_BODY], NULL, error);
+ if (!body)
return FALSE;
- }
- declaration = method_from_method_def_or_ref (image, data [MONO_METHODIMPL_DECLARATION], NULL);
- 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);
+ declaration = method_from_method_def_or_ref (image, data [MONO_METHODIMPL_DECLARATION], NULL, error);
+ if (!declaration)
return FALSE;
- }
/* FIXME
mono_class_setup_supertypes (class);