2009-06-18 Rodrigo Kumpera <rkumpera@novell.com>
authorRodrigo Kumpera <kumpera@gmail.com>
Fri, 19 Jun 2009 01:47:33 +0000 (01:47 -0000)
committerRodrigo Kumpera <kumpera@gmail.com>
Fri, 19 Jun 2009 01:47:33 +0000 (01:47 -0000)
* metadata-verify.c: Finished with method header verification.

svn path=/trunk/mono/; revision=136449

mono/metadata/ChangeLog
mono/metadata/metadata-verify.c

index fdfde74eb61e26f860c0f1ad979f3be2eabeaf2e..4c3c4a87a55f97c5da57f54cf564b2c5b1748633 100644 (file)
@@ -1,3 +1,7 @@
+2009-06-18 Rodrigo Kumpera  <rkumpera@novell.com>
+
+       * metadata-verify.c: Finished with method header verification.
+
 2009-06-18 Rodrigo Kumpera  <rkumpera@novell.com>
 
        * metadata-verify.c: Added more header verification code.
index 5e08d459a6a104e1ea9aa09f9a86eced018cc815..3db7074879e9c8817765e7c5c1b0076f364686a7 100644 (file)
@@ -1873,17 +1873,31 @@ is_valid_method_header (VerifyContext *ctx, guint32 rva)
 
                if (section_size < 4)
                        FAIL (ctx, g_strdup_printf ("MethodHeader: Section size too small"));
-                       
+
                if (ADDP_IS_GREATER_OR_OVF (ptr, section_size - 4, end)) /*must be section_size -4 as ptr was incremented by safe_read32*/
                        FAIL (ctx, g_strdup_printf ("MethodHeader: Not enough room for section content %d", section_size));
 
                if (section_header & METHOD_HEADER_SECTION_EHTABLE) {
-                       guint32 clauses = (section_size - 4) / (is_fat ? 24 : 12);
+                       guint32 i, clauses = (section_size - 4) / (is_fat ? 24 : 12);
                        if (clauses * (is_fat ? 24 : 12) + 4 != section_size)
                                FAIL (ctx, g_strdup_printf ("MethodHeader: Invalid EH section size %d, it's not of the proper size", section_size));
+
+                       /* only verify the class token is verified as the rest is done by the IL verifier*/
+                       for (i = 0; i < clauses; ++i) {
+                               guint32 class_token = 0;
+                               ptr += (is_fat ? 20 : 8);
+                               if (!safe_read32 (class_token, ptr, end))
+                                       FAIL (ctx, g_strdup_printf ("MethodHeader: Not enough room for section %d", i));
+                               if (!*ptr == MONO_EXCEPTION_CLAUSE_NONE && class_token) {
+                                       guint table = mono_metadata_token_table (class_token);
+                                       if (table != MONO_TABLE_TYPEREF && table != MONO_TABLE_TYPEDEF && table != MONO_TABLE_TYPESPEC)
+                                               FAIL (ctx, g_strdup_printf ("MethodHeader: Invalid section %d class token table %x", i, table));
+                                       if (mono_metadata_token_index (class_token) > ctx->image->tables [table].rows)
+                                               FAIL (ctx, g_strdup_printf ("MethodHeader: Invalid section %d class token index %x", i, mono_metadata_token_index (class_token)));
+                               }
+                       }
                }
 
-               //TODO verify the eh clauses
                if (!(section_header & METHOD_HEADER_SECTION_MORE_SECTS))
                        break;
        } while (1);