[runtime] Fix reading past the end of a string when setting the native thread name.
[mono.git] / mono / dis / main.c
index 7b0b5ad3ef1197565c1274b43a3c813abb8415b9..42d735b0f751ed7780406a0b3448bb0ebac2048d 100644 (file)
@@ -30,6 +30,7 @@
 #include <mono/metadata/loader.h>
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/appdomain.h>
+#include <mono/utils/bsearch.h>
 
 static void     setup_filter          (MonoImage *image);
 static gboolean should_include_type   (int idx);
@@ -535,8 +536,8 @@ static dis_map_t method_flags_map [] = {
        { METHOD_ATTRIBUTE_RT_SPECIAL_NAME,     "rtspecialname " },
        { METHOD_ATTRIBUTE_UNMANAGED_EXPORT,    "export " },
 /* MS ilasm doesn't compile this statement - is must be added automagically when permissionset are present */
-/*     { METHOD_ATTRIBUTE_HAS_SECURITY,        "hassecurity" }, */
-       { METHOD_ATTRIBUTE_REQUIRE_SEC_OBJECT,  "requiresecobj" },
+       { METHOD_ATTRIBUTE_HAS_SECURITY,        "" /*"hassecurity"*/ },
+       { METHOD_ATTRIBUTE_REQUIRE_SEC_OBJECT,  "requiresecobj " },
        { METHOD_ATTRIBUTE_PINVOKE_IMPL,        "pinvokeimpl " }, 
        { METHOD_ATTRIBUTE_STRICT,                  "strict " }, 
        { 0, NULL }
@@ -567,10 +568,10 @@ method_flags (guint32 f)
 static dis_map_t pinvoke_flags_map [] = {
        { PINVOKE_ATTRIBUTE_NO_MANGLE ,            "nomangle " },
        { PINVOKE_ATTRIBUTE_SUPPORTS_LAST_ERROR,   "lasterr " },
-       { PINVOKE_ATTRIBUTE_BEST_FIT_ENABLED,      "bestfit:on" },
-       { PINVOKE_ATTRIBUTE_BEST_FIT_DISABLED,      "bestfit:off" },
-       { PINVOKE_ATTRIBUTE_THROW_ON_UNMAPPABLE_ENABLED, "charmaperror:on" },
-       { PINVOKE_ATTRIBUTE_THROW_ON_UNMAPPABLE_DISABLED, "charmaperror:off" },
+       { PINVOKE_ATTRIBUTE_BEST_FIT_ENABLED,      "bestfit:on " },
+       { PINVOKE_ATTRIBUTE_BEST_FIT_DISABLED,      "bestfit:off " },
+       { PINVOKE_ATTRIBUTE_THROW_ON_UNMAPPABLE_ENABLED, "charmaperror:on " },
+       { PINVOKE_ATTRIBUTE_THROW_ON_UNMAPPABLE_DISABLED, "charmaperror:off " },
        { 0, NULL }
 };
 
@@ -859,8 +860,13 @@ dis_method_list (const char *klass_name, MonoImage *m, guint32 start, guint32 en
                        container = type_container;
 
                ms = mono_metadata_parse_method_signature_full (m, container, i + 1, sig, &sig);
-               sig_str = dis_stringify_method_signature (m, ms, i + 1, container, FALSE);
-               method_name = mono_metadata_string_heap (m, cols [MONO_METHOD_NAME]);
+               if (ms != NULL){
+                       sig_str = dis_stringify_method_signature (m, ms, i + 1, container, FALSE);
+                       method_name = mono_metadata_string_heap (m, cols [MONO_METHOD_NAME]);
+               } else {
+                       sig_str = NULL;
+                       method_name = g_strdup ("<NULL METHOD SIGNATURE>");
+               }
 
                fprintf (output, "    // method line %d\n", i + 1);
                fprintf (output, "    .method %s", flags);
@@ -1104,7 +1110,7 @@ dis_interfaces (MonoImage *m, guint32 typedef_row, MonoGenericContainer *contain
        loc.col_idx = MONO_INTERFACEIMPL_CLASS;
        loc.idx = typedef_row;
 
-       if (!bsearch (&loc, table->base, table->rows, table->row_size, table_locator))
+       if (!mono_binary_search (&loc, table->base, table->rows, table->row_size, table_locator))
                return;
 
        start = loc.result;
@@ -1675,7 +1681,7 @@ table_includes (TableFilter *tf, int idx)
 {
        if (!tf->count)
                return FALSE;
-       return bsearch (&idx, tf->elems, tf->count, sizeof (int), int_cmp) != NULL;
+       return mono_binary_search (&idx, tf->elems, tf->count, sizeof (int), int_cmp) != NULL;
 }
 
 static gboolean