[Mono-bugs] [Bug 62358][Nor] New - MCS doesn't encode SecurityAttributes properly

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 3 Aug 2004 09:26:20 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by sebastien@ximian.com.

http://bugzilla.ximian.com/show_bug.cgi?id=62358

--- shadow/62358	2004-08-03 09:26:20.000000000 -0400
+++ shadow/62358.tmp.8183	2004-08-03 09:26:20.000000000 -0400
@@ -0,0 +1,223 @@
+Bug#: 62358
+Product: Mono: Compilers
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: sebastien@ximian.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: MCS doesn't encode SecurityAttributes properly
+
+Description of Problem:
+MCS encodes "SecurityAttribute"s like any other Attribute. Attributes
+deriving from SecurityAttributes should be XML encoded in the assembly
+metadata.
+
+
+Steps to reproduce the problem:
+1. Source code sample
+
+using System;
+using System.Security;
+using System.Security.Permissions;
+
+[assembly: SecurityPermission (SecurityAction.RequestMinimum, Execution=true)]
+[assembly: SecurityPermission (SecurityAction.RequestOptional,
+Unrestricted=true)]
+[assembly: SecurityPermission (SecurityAction.RequestRefuse,
+SkipVerification=true)]
+
+[SecurityPermission (SecurityAction.Demand, ControlAppDomain=true)]
+public class Program {
+
+	[SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
+	static public void Main (string[] args)
+	{
+		Console.WriteLine ("Hello Mono!");
+	}
+}
+
+2. Compile the previous code with MCS and disassemble it
+3. Compile the previous code with CSC and disassemble it
+
+
+Actual Results (compiled with MCS / disassembled by monodis):
+
+.assembly extern mscorlib
+{
+  .ver 1:0:5000:0
+}
+.assembly 'secattrs'
+{
+  .custom instance void class
+[mscorlib]System.Security.Permissions.SecurityPermissionAttribute::.ctor(valuetype
+[mscorlib]System.Security.Permissions.SecurityAction) =  (
+		01 00 08 00 00 00 01 00 54 02 09 45 78 65 63 75   // ........T..Execu
+		74 69 6F 6E 01                                  ) // tion.
+
+  .custom instance void class
+[mscorlib]System.Security.Permissions.SecurityPermissionAttribute::.ctor(valuetype
+[mscorlib]System.Security.Permissions.SecurityAction) =  (
+		01 00 09 00 00 00 01 00 54 02 0C 55 6E 72 65 73   // ........T..Unres
+		74 72 69 63 74 65 64 01                         ) // tricted..assembly
+extern mscorlib
+{
+  .ver 1:0:5000:0
+}
+.assembly 'secattrs'
+{
+  .custom instance void class
+[mscorlib]System.Security.Permissions.SecurityPermissionAttribute::.ctor(valuetype
+[mscorlib]System.Security.Permissions.SecurityAction) =  (
+		01 00 08 00 00 00 01 00 54 02 09 45 78 65 63 75   // ........T..Execu
+		74 69 6F 6E 01                                  ) // tion.
+
+  .custom instance void class
+[mscorlib]System.Security.Permissions.SecurityPermissionAttribute::.ctor(valuetype
+[mscorlib]System.Security.Permissions.SecurityAction) =  (
+		01 00 09 00 00 00 01 00 54 02 0C 55 6E 72 65 73   // ........T..Unres
+		74 72 69 63 74 65 64 01                         ) // tricted.
+
+  .custom instance void class
+[mscorlib]System.Security.Permissions.SecurityPermissionAttribute::.ctor(valuetype
+[mscorlib]System.Security.Permissions.SecurityAction) =  (
+		01 00 0A 00 00 00 01 00 54 02 10 53 6B 69 70 56   // ........T..SkipV
+		65 72 69 66 69 63 61 74 69 6F 6E 01             ) // erification.
+
+  .hash algorithm 0x00008004
+  .ver  0:0:0:0
+}
+.module secattrs.exe // GUID = {4253E319-1732-4D0F-874E-405AE51B30D5}
+
+
+  .class public auto ansi beforefieldinit Program
+  	extends [mscorlib]System.Object
+  {
+    .custom instance void class
+[mscorlib]System.Security.Permissions.SecurityPermissionAttribute::.ctor(valuetype
+[mscorlib]System.Security.Permissions.SecurityAction) =  (
+		01 00 02 00 00 00 01 00 54 02 10 43 6F 6E 74 72   // ........T..Contr
+		6F 6C 41 70 70 44 6F 6D 61 69 6E 01             ) // olAppDomain.
+
+
+    // method line 1
+    .method public hidebysig  specialname  rtspecialname 
+           instance default void .ctor ()  cil managed 
+    {
+        // Method begins at RVA 0x20ec
+	// Code size 7 (0x7)
+	.maxstack 8
+	IL_0000:  ldarg.0 
+	IL_0001:  call instance void class [mscorlib]System.Object::.ctor()
+	IL_0006:  ret 
+    } // end of method Program::instance default void .ctor () 
+
+    // method line 2
+    .method public static  hidebysig 
+           default void Main (string[] args)  cil managed 
+    {
+        .custom instance void class
+[mscorlib]System.Security.Permissions.SecurityPermissionAttribute::.ctor(valuetype
+[mscorlib]System.Security.Permissions.SecurityAction) =  (
+		01 00 02 00 00 00 01 00 54 02 10 43 6F 6E 74 72   // ........T..Contr
+		6F 6C 50 72 69 6E 63 69 70 61 6C 01             ) // olPrincipal.
+
+	.param [1]
+        // Method begins at RVA 0x20f4
+	.entrypoint
+	// Code size 11 (0xb)
+	.maxstack 8
+	IL_0000:  ldstr "Hello Mono!"
+	IL_0005:  call void class [mscorlib]System.Console::WriteLine(string)
+	IL_000a:  ret 
+    } // end of method Program::default void Main (string[] args) 
+
+  } // end of class Program
+
+
+  .custom instance void class
+[mscorlib]System.Security.Permissions.SecurityPermissionAttribute::.ctor(valuetype
+[mscorlib]System.Security.Permissions.SecurityAction) =  (
+		01 00 0A 00 00 00 01 00 54 02 10 53 6B 69 70 56   // ........T..SkipV
+		65 72 69 66 69 63 61 74 69 6F 6E 01             ) // erification.
+
+  .hash algorithm 0x00008004
+  .ver  0:0:0:0
+}
+.module secattrs.exe // GUID = {4253E319-1732-4D0F-874E-405AE51B30D5}
+
+
+  .class public auto ansi beforefieldinit Program
+  	extends [mscorlib]System.Object
+  {
+    .custom instance void class
+[mscorlib]System.Security.Permissions.SecurityPermissionAttribute::.ctor(valuetype
+[mscorlib]System.Security.Permissions.SecurityAction) =  (
+		01 00 02 00 00 00 01 00 54 02 10 43 6F 6E 74 72   // ........T..Contr
+		6F 6C 41 70 70 44 6F 6D 61 69 6E 01             ) // olAppDomain.
+
+
+    // method line 1
+    .method public hidebysig  specialname  rtspecialname 
+           instance default void .ctor ()  cil managed 
+    {
+        // Method begins at RVA 0x20ec
+	// Code size 7 (0x7)
+	.maxstack 8
+	IL_0000:  ldarg.0 
+	IL_0001:  call instance void class [mscorlib]System.Object::.ctor()
+	IL_0006:  ret 
+    } // end of method Program::instance default void .ctor () 
+
+    // method line 2
+    .method public static  hidebysig 
+           default void Main (string[] args)  cil managed 
+    {
+        .custom instance void class
+[mscorlib]System.Security.Permissions.SecurityPermissionAttribute::.ctor(valuetype
+[mscorlib]System.Security.Permissions.SecurityAction) =  (
+		01 00 02 00 00 00 01 00 54 02 10 43 6F 6E 74 72   // ........T..Contr
+		6F 6C 50 72 69 6E 63 69 70 61 6C 01             ) // olPrincipal.
+
+	.param [1]
+        // Method begins at RVA 0x20f4
+	.entrypoint
+	// Code size 11 (0xb)
+	.maxstack 8
+	IL_0000:  ldstr "Hello Mono!"
+	IL_0005:  call void class [mscorlib]System.Console::WriteLine(string)
+	IL_000a:  ret 
+    } // end of method Program::default void Main (string[] args) 
+
+  } // end of class Program
+
+
+
+Expected Results (compiled with CSC / disassembled by ildasm):
+
+(too big see attachement)
+
+
+How often does this happen? 
+Always as current MCS source code doesn't seems to be using
+AddDeclarativeSecurity anywhere.
+
+
+Additional Information:
+
+* Section 5 of the document "DeclarativeSecuritySupport.doc" has some
+information on how to encode security attributes from managed code.
+
+* This also adds "false" additions (attributes) to corcompare results.
+
+* The same issue probably applies to other compilers / assembler.
+
+* Workaround is to use CSC to compile the assemblies.