Merge pull request #3446 from lambdageek/bug-42584
authorAleksey Kliger (λgeek) <akliger@gmail.com>
Fri, 2 Sep 2016 14:31:42 +0000 (10:31 -0400)
committerGitHub <noreply@github.com>
Fri, 2 Sep 2016 14:31:42 +0000 (10:31 -0400)
[loader] Check for ReferenceAssemblyAttribute when loading

12 files changed:
mcs/class/corlib/Mono.Security/Uri.cs
mcs/class/corlib/System.Security.Policy/Zone.cs
mcs/class/corlib/System/AppDomainSetup.cs
mcs/class/corlib/Test/System.Globalization/CultureInfoTest.cs
mcs/class/corlib/Test/System.Security.Policy/ZoneTest.cs
mcs/class/corlib/Test/System/AppDomainSetupTest.cs
mcs/class/dlr/Runtime/Microsoft.Scripting.Core/Actions/DynamicObject.cs
mcs/mcs/cs-tokenizer.cs
mcs/tests/dtest-065.cs [new file with mode: 0644]
mcs/tests/test-debug-30-ref.xml
mcs/tests/test-debug-30.cs
mcs/tests/ver-il-net_4_x.xml

index 104516c3e934b25c896330bf7df3f381d7eaafca..9be2deb9e2e84f2db87abe40b6968dd4eaf685d3 100644 (file)
@@ -1015,7 +1015,7 @@ namespace Mono.Security {
                        }
                        
                        // 5 path
-                       pos = uriString.IndexOfAny (new char[] {'/'});
+                       pos = uriString.IndexOfAny (new char[] {'/', '\\'});
                        if (unixAbsPath)
                                pos = -1;
                        if (pos == -1) {
@@ -1042,6 +1042,8 @@ namespace Mono.Security {
                        pos = uriString.LastIndexOf (":");
                        if (unixAbsPath)
                                pos = -1;
+                       if (pos == 1 && scheme == Uri.UriSchemeFile && Char.IsLetter (uriString [0]))
+                               pos = -1;
                        if (pos != -1 && pos != (uriString.Length - 1)) {
                                string portStr = uriString.Remove (0, pos + 1);
                                if (portStr.Length > 1 && portStr [portStr.Length - 1] != ']') {
index b65d55460d4fde6b99f69ec029a2da815ff45ea5..64826f938eb50a5a2568a0628d311a5b17f0ddcb 100644 (file)
@@ -83,7 +83,13 @@ namespace System.Security.Policy {
                        if (url.Length == 0)
                                return new Zone (z);
 
-                       Uri uri = new Uri (url);
+                       Uri uri = null;
+                       try {
+                               uri = new Uri (url);
+                       }
+                       catch {
+                               return new Zone (z);
+                       }
                        // TODO: apply zone configuration
                        // this is the only way to use the Trusted and Untrusted zones
 
index c1865f34bd366939da81af189dc94ab10a203ce4..309535cfdd7e4ba32f2f55e8d86bdf6ab733a71e 100644 (file)
@@ -36,6 +36,7 @@ using System.IO;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Security;
+using System.Security.Permissions;
 using System.Runtime.Serialization.Formatters.Binary;
 
 using System.Runtime.Hosting;
@@ -139,14 +140,19 @@ namespace System
                                appBase = appBase.Substring (7);
                                if (Path.DirectorySeparatorChar != '/')
                                        appBase = appBase.Replace ('/', Path.DirectorySeparatorChar);
-                               if (Environment.IsRunningOnWindows) {
-                                       // Under Windows prepend "//" to indicate it's a local file
-                                       appBase = "//" + appBase;
+                       }
+                       appBase = Path.GetFullPath (appBase);
+
+                       if (Path.DirectorySeparatorChar != '/') {
+                               bool isExtendedPath = appBase.StartsWith (@"\\?\", StringComparison.Ordinal);
+                               if (appBase.IndexOf (':', isExtendedPath ? 6 : 2) != -1) {
+                                       throw new NotSupportedException ("The given path's format is not supported.");
                                }
-                       } else {
-                               appBase = Path.GetFullPath (appBase);
                        }
 
+                       // Trigger a validation of the path
+                       new FileIOPermission (FileIOPermissionAccess.PathDiscovery, appBase);
+
                        return appBase;
                }
 
index 124aacd130248c037dac8a37f8ced82b6e8962a4..73bfa734fa842390426dbbd1a8cc660c7bce12a7 100644 (file)
@@ -743,7 +743,7 @@ namespace MonoTests.System.Globalization
                        var expected = 100000.ToString ("C");
 
                        thread.Start ();
-                       thread.Join ();
+                       Assert.IsTrue (thread.Join (5000), "#0");
                        CultureInfo.DefaultThreadCurrentCulture = null;
                        Assert.AreEqual (expected, us_str, "#1");
                        Assert.AreEqual (expected, br_str, "#2");
index 00aa374348db05be7dae57d541cf5275cc326c31..f75b723ff45947e8b9fab4c54e1c47e48f539c18 100644 (file)
@@ -229,7 +229,7 @@ namespace MonoTests.System.Security.Policy {
                        "http://*.go-mono.com",
                        "http://www.go-mono.com:8080/index.html",
                        "mono://unknown/protocol",
-                       Path.DirectorySeparatorChar + "mono" + Path.DirectorySeparatorChar + "index.html",
+                       "/mono/index.html",
                };
 
                [Test]
index 121d1c45f10a88ceae0f80fdbbfe3575d7f7cb70..387d0318a3f45cc6eb627e3241dd6ad2bd40704a 100644 (file)
@@ -23,8 +23,12 @@ namespace MonoTests.System
 
                private bool RunningOnWindows {
                        get {
-                               int os = (int)Environment.OSVersion.Platform;
-                               return (os != 4);
+                               return Path.DirectorySeparatorChar == '\\';
+                       }
+               }
+               private bool RunningOnMono {
+                       get {
+                               return (Type.GetType ("System.MonoType", false) != null);
                        }
                }
 
@@ -72,22 +76,18 @@ namespace MonoTests.System
                [Test]
                public void ApplicationBase1 ()
                {
-                       string expected_path = tmpPath.Replace(@"\", @"/");
+                       string expected_path = tmpPath;
                        AppDomainSetup setup = new AppDomainSetup ();
-                       string fileUri = "file://" + expected_path;
+                       string fileUri = "file://" + tmpPath.Replace(@"\", @"/");
                        setup.ApplicationBase = fileUri;
-                       // with MS 1.1 SP1 the expected_path starts with "//" but this make
-                       // sense only under Windows (i.e. reversed \\ for local files)
-                       if (RunningOnWindows)
-                               expected_path = "//" + expected_path;
                        try {
-                               // under 2.0 the NotSupportedException is throw when getting 
+                               // under .NET the NotSupportedException is throw when getting 
                                // (and not setting) the ApplicationBase property
                                Assert.AreEqual (expected_path, setup.ApplicationBase);
                        }
                        catch (NotSupportedException) {
-                               // however the path is invalid only on Windows
-                               if (!RunningOnWindows)
+                               // however the path is invalid only on .NET
+                               if (RunningOnMono)
                                        throw;
                        }
                }
@@ -114,16 +114,17 @@ namespace MonoTests.System
                {
                        AppDomainSetup setup = new AppDomainSetup ();
                        setup.ApplicationBase = "lala:la";
-                       try {
-                               // under 2.0 the NotSupportedException is throw when getting 
-                               // (and not setting) the ApplicationBase property
+                       if (!RunningOnWindows) {
                                Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
-                       }
-                       catch (NotSupportedException) {
-                               // however the path is invalid only on Windows
-                               // (same exceptions as Path.GetFullPath)
-                               if (!RunningOnWindows)
-                                       throw;
+                       } else {
+                               // On Windows we expect a NotSupportedException to be thrown because
+                               // of the illegal character (:) in the path
+                               try {
+                                       Assert.Fail ("NotSupportedException expected but setup.ApplicationBase returned:" + setup.ApplicationBase);
+                               }
+                               catch (NotSupportedException) {
+                                       // Expected
+                               }
                        }
                }
 
@@ -133,16 +134,18 @@ namespace MonoTests.System
                        // This is failing because of (probably) a windows-ism, so don't worry
                        AppDomainSetup setup = new AppDomainSetup ();
                        setup.ApplicationBase = "file:///lala:la";
-                       try {
-                               // under 2.0 the NotSupportedException is throw when getting 
-                               // (and not setting) the ApplicationBase property
-                               Assert.AreEqual ("/lala:la", setup.ApplicationBase);
-                       }
-                       catch (NotSupportedException) {
-                               // however the path is invalid only on Windows
-                               // (same exceptions as Path.GetFullPath)
-                               if (!RunningOnWindows)
-                                       throw;
+                       string expected = "/lala:la";
+                       if (!RunningOnWindows) {
+                               Assert.AreEqual (expected, setup.ApplicationBase);
+                       } else {
+                               // On Windows we expect a NotSupportedException to be thrown because
+                               // of the illegal character (:) in the path
+                               try {
+                                       Assert.Fail ("NotSupportedException expected but setup.ApplicationBase returned:" + setup.ApplicationBase);
+                               }
+                               catch (NotSupportedException) {
+                                       // Expected
+                               }
                        }
                }
 
@@ -153,19 +156,45 @@ namespace MonoTests.System
                        setup.ApplicationBase = "la?lala";
                        // paths containing "?" are *always* bad on Windows
                        // but are legal for linux so we return a full path
-                       if (RunningOnWindows) {
+                       if (!RunningOnWindows) {
+                               Assert.AreEqual (Path.GetFullPath ("la?lala"), setup.ApplicationBase);
+                       } else {
+                               // On Windows we expect a ArgumentException to be thrown because
+                               // of the illegal character (?) in the path
                                try {
-                                       // ArgumentException is throw when getting 
-                                       // (and not setting) the ApplicationBase property
-                                       Assert.Fail ("setup.ApplicationBase returned :" + setup.ApplicationBase);
+                                       Assert.Fail ("ArgumentException expected but setup.ApplicationBase returned:" + setup.ApplicationBase);
                                }
                                catch (ArgumentException) {
+                                       // Expected
+                               }
+                       }
+               }
+
+               [Test]
+               public void ApplicationBase7 ()
+               {
+                       if (RunningOnWindows) {
+                               // Extended paths are Windows only
+                               AppDomainSetup setup = new AppDomainSetup ();
+                               string expected = @"\\?\" + curDir;
+                               setup.ApplicationBase = expected;
+                               Assert.AreEqual (expected, setup.ApplicationBase);
+                       }
+               }
+
+               [Test]
+               public void ApplicationBase8 ()
+               {
+                       if (RunningOnWindows) {
+                               // Extended paths are Windows only
+                               AppDomainSetup setup = new AppDomainSetup ();
+                               setup.ApplicationBase = @"\\?\C:\lala:la";
+                               try {
+                                       Assert.Fail ("NotSupportedException expected but setup.ApplicationBase returned:" + setup.ApplicationBase);
                                }
-                               catch (Exception e) {
-                                       Assert.Fail ("Unexpected exception: " + e.ToString ());
+                               catch (NotSupportedException) {
+                                       // Expected
                                }
-                       } else {
-                               Assert.AreEqual (Path.GetFullPath ("la?lala"), setup.ApplicationBase);
                        }
                }
 
index 71341f5bc2dc3d83de248228b9d237b2d0d70b16..7da7303d755466e2c3bcdb87b7800fe0e914594a 100644 (file)
@@ -501,6 +501,44 @@ namespace System.Dynamic {
                         binder.ReturnType
                     );
 
+#if MONO // referencesource version
+                    Expression condition;
+                    // If the return type can not be assigned null then just check for type assignablity otherwise allow null.
+                    if (binder.ReturnType.IsValueType && Nullable.GetUnderlyingType(binder.ReturnType) == null) {
+                        condition = Expression.TypeIs(resultMO.Expression, binder.ReturnType);
+                    }
+                    else {
+                        condition = Expression.OrElse(
+                                        Expression.Equal(resultMO.Expression, Expression.Constant(null)),
+                                        Expression.TypeIs(resultMO.Expression, binder.ReturnType));
+                    }
+
+                    var checkedConvert = Expression.Condition(
+                        condition,
+                        convert,
+                        Expression.Throw(
+                            Expression.New(typeof(InvalidCastException).GetConstructor(new Type[]{typeof(string)}),
+                                Expression.Call(
+                                    typeof(string).GetMethod("Format", new Type[] {typeof(string), typeof(object[])}),
+                                    Expression.Constant(convertFailed),
+                                    Expression.NewArrayInit(typeof(object),
+                                        Expression.Condition(
+                                            Expression.Equal(resultMO.Expression, Expression.Constant(null)),
+                                            Expression.Constant("null"),
+                                            Expression.Call(
+                                                resultMO.Expression,
+                                                typeof(object).GetMethod("GetType")
+                                            ),
+                                            typeof(object)
+                                        )
+                                    )
+                                )
+                            ),
+                            binder.ReturnType
+                        ),
+                        binder.ReturnType
+                    );
+#else
                     var checkedConvert = Expression.Condition(
                         Expression.TypeIs(resultMO.Expression, binder.ReturnType),
                         convert,
@@ -524,6 +562,7 @@ namespace System.Dynamic {
                         ),
                         binder.ReturnType
                     );
+#endif
 
                     resultMO = new DynamicMetaObject(checkedConvert, resultMO.Restrictions);
                 }
index 1c63e70b91d269a9f647f0505a8377731bbd0c98..1915a07240b379fdf4443385f6bd5a0af1e07783 100644 (file)
@@ -2562,6 +2562,9 @@ namespace Mono.CSharp
                                                                        pow /= 10;
                                                                }
                                                        }
+                                               } else if (c == '\n' || c == UnicodeLS || c == UnicodePS) {
+                                                       advance_line ();
+                                                       break;
                                                } else if ((c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_') {
                                                        break;
                                                }
@@ -2587,9 +2590,6 @@ namespace Mono.CSharp
                                while (c == ' ' || c == '\t')
                                        c = get_char ();
 
-                               if (c == '\n' || c == UnicodeLS || c == UnicodePS)
-                                       advance_line ();
-
                                return number;
                        }
 
diff --git a/mcs/tests/dtest-065.cs b/mcs/tests/dtest-065.cs
new file mode 100644 (file)
index 0000000..fb51a71
--- /dev/null
@@ -0,0 +1,28 @@
+using System.Dynamic;
+
+public class TestConvert : DynamicObject
+{
+       public override bool TryConvert (ConvertBinder binder, out object result)
+       {
+               result = null;
+               return true;
+       }
+}
+
+public class Test : DynamicObject
+{
+       public override bool TryInvokeMember (InvokeMemberBinder binder, object [] args, out object result)
+       {
+               result = new TestConvert ();
+               return true;
+       }
+}
+
+public class XX
+{
+       public static void Main ()
+       {
+               dynamic t = new Test ();
+               string result = t.SomeMethod ();
+       }
+}
\ No newline at end of file
index 461f6573e595c09f20e31b96fea3787550c331a1..34ed22655308b7fe7348feac6132a032a4b21206 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <symbols>
   <files>
-    <file id="1" name="test-debug-30.cs" checksum="d3addfa69f16faf00991ef839451a975" />
+    <file id="1" name="test-debug-30.cs" checksum="5303b32b0208123737567d53022ae3d5" />
   </files>
   <methods>
     <method token="0x6000001">
       <locals />
       <scopes />
     </method>
+    <method token="0x6000004">
+      <sequencepoints>
+        <entry il="0x0" row="23" col="2" file_ref="1" hidden="false" />
+        <entry il="0x1" row="24" col="3" file_ref="1" hidden="false" />
+        <entry il="0x6" row="25" col="2" file_ref="1" hidden="false" />
+      </sequencepoints>
+      <locals />
+      <scopes />
+    </method>
   </methods>
 </symbols>
\ No newline at end of file
index 78f0cdfe3c74a9e6b6631ef20e0e6e0616c577e7..a72f014101ee2392d3d532080ee712a51d06158c 100644 (file)
@@ -15,4 +15,12 @@ class PragmaNewLinesParsing
        {
                return;
        }
+
+#pragma warning disable 618
+#pragma warning restore 618
+
+       void OneMore ()
+       {
+               return;
+       }
 }
\ No newline at end of file
index cde4e9e70d68ea66bba24d1169045aa8b6be1057..67147f16a7725c577a9bc49dba24b87f69d56296 100644 (file)
       </method>
     </type>
   </test>
+  <test name="dtest-065.cs">
+    <type name="TestConvert">
+      <method name="Boolean TryConvert(System.Dynamic.ConvertBinder, System.Object ByRef)" attrs="198">
+        <size>13</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="Test">
+      <method name="Boolean TryInvokeMember(System.Dynamic.InvokeMemberBinder, System.Object[], System.Object ByRef)" attrs="198">
+        <size>17</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="XX">
+      <method name="Void Main()" attrs="150">
+        <size>154</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="dtest-anontype-01.cs">
     <type name="C">
       <method name="Void Main()" attrs="150">
       <method name="Void .ctor()" attrs="6278">
         <size>7</size>
       </method>
+      <method name="Void OneMore()" attrs="129">
+        <size>7</size>
+      </method>
     </type>
   </test>
   <test name="test-decl-expr-01.cs">