2010-04-23 Jb Evain <jbevain@novell.com>
authorJb Evain <jbevain@gmail.com>
Fri, 23 Apr 2010 17:00:56 +0000 (17:00 -0000)
committerJb Evain <jbevain@gmail.com>
Fri, 23 Apr 2010 17:00:56 +0000 (17:00 -0000)
* domain.c (get_runtime_by_version): renamed to
mono_get_runtime_by_version.

* domain-internals.h: expose mono_get_runtime_by_version as
an internal function.

* assembly.c (mono_assembly_load_from_full): check if the image
references a newer runtime than the current executing one, and
mark it as invalid if it's the case.

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

mono/metadata/ChangeLog
mono/metadata/assembly.c
mono/metadata/domain-internals.h
mono/metadata/domain.c

index e30fbf25672339335daa369b471593eb7181dbcf..50bdf2606e85124b137a863bdf708bc3b6fb1f4a 100644 (file)
@@ -1,3 +1,15 @@
+2010-04-23  Jb Evain  <jbevain@novell.com>
+
+       * domain.c (get_runtime_by_version): renamed to
+       mono_get_runtime_by_version.
+
+       * domain-internals.h: expose mono_get_runtime_by_version as
+       an internal function.
+
+       * assembly.c (mono_assembly_load_from_full): check if the image
+       references a newer runtime than the current executing one, and
+       mark it as invalid if it's the case.
+
 2010-04-23 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * threadpool.c: patch from Robert Nagy that fixes a nullref and
index a33d726d3a6d7c1b1f6c96c03dde229f002c477a..797274edf89da7345a9be1774b591a614531b280 100644 (file)
@@ -1470,6 +1470,26 @@ mono_assembly_open (const char *filename, MonoImageOpenStatus *status)
        return mono_assembly_open_full (filename, status, FALSE);
 }
 
+static gboolean
+image_references_newer_runtime (MonoImage *image)
+{
+       const char *image_version, *current_version;
+       gint i, cmp;
+
+       image_version = mono_get_runtime_by_version (image->version)->framework_version;
+       current_version = mono_get_runtime_info ()->framework_version;
+
+       for (i = 0; i < 4; i++) {
+               cmp = (image_version [i] - '0') - (current_version [0] - '0');
+               if (cmp > 0)
+                       return TRUE;
+               else if (cmp < 0)
+                       return FALSE;
+       }
+
+       return FALSE;
+}
+
 MonoAssembly *
 mono_assembly_load_from_full (MonoImage *image, const char*fname, 
                              MonoImageOpenStatus *status, gboolean refonly)
@@ -1483,6 +1503,11 @@ mono_assembly_load_from_full (MonoImage *image, const char*fname,
                return NULL;
        }
 
+       if (image_references_newer_runtime (image)) {
+               *status = MONO_IMAGE_IMAGE_INVALID;
+               return NULL;            
+       }
+
 #if defined (HOST_WIN32)
        {
                gchar *tmp_fn;
index c4579ebe128009ee231c34a394d75a9452228af3..f5379242952769906559dc1942892192ba37f88e 100644 (file)
@@ -517,6 +517,9 @@ mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *
 const MonoRuntimeInfo*
 mono_get_runtime_info (void) MONO_INTERNAL;
 
+const MonoRuntimeInfo*
+mono_get_runtime_by_version (const char *version) MONO_INTERNAL;
+
 void
 mono_runtime_set_no_exec (gboolean val) MONO_INTERNAL;
 
index 7349c6cb28c0b63896be7ee00fcef61ffc553387..f3d5afa084de66e6a7ab1d0c7415e63ea436e2d4 100644 (file)
@@ -149,9 +149,6 @@ extern void _mono_debug_init_corlib (MonoDomain *domain);
 static void
 get_runtimes_from_exe (const char *exe_file, MonoImage **exe_image, const MonoRuntimeInfo** runtimes);
 
-static const MonoRuntimeInfo*
-get_runtime_by_version (const char *version);
-
 static MonoImage*
 mono_jit_info_find_aot_module (guint8* addr);
 
@@ -1316,12 +1313,12 @@ mono_init_internal (const char *filename, const char *exe_filename, const char *
                mono_fixup_exe_image (exe_image);
 #endif
        } else if (runtime_version != NULL) {
-               runtimes [0] = get_runtime_by_version (runtime_version);
+               runtimes [0] = mono_get_runtime_by_version (runtime_version);
                runtimes [1] = NULL;
        }
 
        if (runtimes [0] == NULL) {
-               const MonoRuntimeInfo *default_runtime = get_runtime_by_version (DEFAULT_RUNTIME_VERSION);
+               const MonoRuntimeInfo *default_runtime = mono_get_runtime_by_version (DEFAULT_RUNTIME_VERSION);
                runtimes [0] = default_runtime;
                runtimes [1] = NULL;
                g_print ("WARNING: The runtime version supported by this application is unavailable.\n");
@@ -2490,9 +2487,13 @@ app_config_free (AppConfigInfo* app_config)
        g_free (app_config);
 }
 
-
-static const MonoRuntimeInfo*
-get_runtime_by_version (const char *version)
+/**
+ * mono_get_runtime_by_version:
+ *
+ * Returns: the runtime info for the specified version.
+ */
+const MonoRuntimeInfo*
+mono_get_runtime_by_version (const char *version)
 {
        int n;
        int max = G_N_ELEMENTS (supported_runtimes);
@@ -2523,7 +2524,7 @@ get_runtimes_from_exe (const char *exe_file, MonoImage **exe_image, const MonoRu
                        GSList *list = app_config->supported_runtimes;
                        while (list != NULL) {
                                version = (char*) list->data;
-                               runtime = get_runtime_by_version (version);
+                               runtime = mono_get_runtime_by_version (version);
                                if (runtime != NULL)
                                        runtimes [n++] = runtime;
                                list = g_slist_next (list);
@@ -2535,7 +2536,7 @@ get_runtimes_from_exe (const char *exe_file, MonoImage **exe_image, const MonoRu
                
                /* Check the requiredRuntime element. This is for 1.0 apps only. */
                if (app_config->required_runtime != NULL) {
-                       runtimes [0] = get_runtime_by_version (app_config->required_runtime);
+                       runtimes [0] = mono_get_runtime_by_version (app_config->required_runtime);
                        runtimes [1] = NULL;
                        app_config_free (app_config);
                        return;
@@ -2554,14 +2555,14 @@ get_runtimes_from_exe (const char *exe_file, MonoImage **exe_image, const MonoRu
                 * a default runtime and leave to the initialization method the work of
                 * reporting the error.
                 */
-               runtimes [0] = get_runtime_by_version (DEFAULT_RUNTIME_VERSION);
+               runtimes [0] = mono_get_runtime_by_version (DEFAULT_RUNTIME_VERSION);
                runtimes [1] = NULL;
                return;
        }
 
        *exe_image = image;
 
-       runtimes [0] = get_runtime_by_version (image->version);
+       runtimes [0] = mono_get_runtime_by_version (image->version);
        runtimes [1] = NULL;
 }