[Mono-bugs] [Bug 352586] New: [PATCH] Certain sequences of ModuleDefinition. Import can cause NRE

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Jan 9 05:40:24 EST 2008


https://bugzilla.novell.com/show_bug.cgi?id=352586


           Summary: [PATCH] Certain sequences of ModuleDefinition.Import can
                    cause NRE
           Product: Mono: Class Libraries
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Cecil
        AssignedTo: jbevain at novell.com
        ReportedBy: rkvinge at novell.com
         QAContact: mono-bugs at ximian.com
          Found By: ---


Repro:
using System.Collections.Generic;
using System;
using System.Reflection;
using System.Reflection.Emit;
using Mono.Cecil;
using Mono.Cecil.Cil;

class t
{
    static void Main()
    {
        AssemblyDefinition a = AssemblyFactory.DefineAssembly("cecil",
AssemblyKind.Dll);
        MethodReference mr;
        TypeReference tr;
        tr =
       
a.MainModule.Import(typeof(System.Collections.Generic.IList<>).GetInterfaces()[0]);
        Console.WriteLine(typeof(IList<>).GetInterfaces()[0].ToString());
        mr =
       
a.MainModule.Import(typeof(System.Collections.Generic.IList<>).GetInterfaces()[0].GetProperty("Count").GetGetMethod());
        Console.WriteLine(mr.ToString());
    }

}

Result:
G:\Volatile\head\mcs\class\Mono.Cecil\bin\Debug>csc *.cs -r:Mono.Cecil.dll &&
cecil-1.exe
Compilador de Microsoft (R) Visual C# 2005 versión 8.00.50727.1433
para Microsoft (R) Windows (R) 2005 Framework versión 2.0.50727
(C) Microsoft Corporation 2001-2005. Reservados todos los derechos.

System.Collections.Generic.ICollection`1[T]

Excepción no controlada: System.NullReferenceException: Referencia a objeto no
establecida como instancia de un objeto.
   en Mono.Cecil.ReflectionHelper.GetGenericParameter(Type t, ImportContext
context) en
G:\Volatile\head\mcs\class\Mono.Cecil\Mono.Cecil\ReflectionHelper.cs:línea 171
   en Mono.Cecil.ReflectionHelper.ImportSystemType(Type t, ImportContext
context) en
G:\Volatile\head\mcs\class\Mono.Cecil\Mono.Cecil\ReflectionHelper.cs:línea 218
   en Mono.Cecil.ReflectionHelper.GetGenericType(Type t, TypeReference element,
ImportContext context) en
G:\Volatile\head\mcs\class\Mono.Cecil\Mono.Cecil\ReflectionHelper.cs:línea 155
   en Mono.Cecil.ReflectionHelper.GetTypeSpec(Type t, ImportContext context) en
G:\Volatile\head\mcs\class\Mono.Cecil\Mono.Cecil\ReflectionHelper.cs:línea 204
   en Mono.Cecil.ReflectionHelper.ImportSystemType(Type t, ImportContext
context) en
G:\Volatile\head\mcs\class\Mono.Cecil\Mono.Cecil\ReflectionHelper.cs:línea 215
   en Mono.Cecil.ReflectionHelper.ImportMethodBase(MethodBase mb, Type retType,
ImportContext context) en
G:\Volatile\head\mcs\class\Mono.Cecil\Mono.Cecil\ReflectionHelper.cs:línea 343
   en Mono.Cecil.ReflectionHelper.ImportMethodInfo(MethodInfo mi, ImportContext
context) en
G:\Volatile\head\mcs\class\Mono.Cecil\Mono.Cecil\ReflectionHelper.cs:línea 370
   en Mono.Cecil.ModuleDefinition.Import(MethodBase meth) en
G:\Volatile\head\mcs\class\Mono.Cecil\Mono.Cecil\ModuleDefinition.cs:línea 246
   en t.Main()

Proposed patch:

Index: ReflectionHelper.cs
===================================================================
--- ReflectionHelper.cs (revision 92488)
+++ ReflectionHelper.cs (working copy)
@@ -212,6 +222,7 @@
                                if (t.IsValueType && !type.IsValueType)
                                        type.IsValueType = true;

+                               context.GenericContext.Type = type;
                                return type;
                        }


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list