[375182] Check AssemblyFileVersion version value
authorMarek Safar <marek.safar@gmail.com>
Tue, 11 Jan 2011 19:14:43 +0000 (19:14 +0000)
committerMarek Safar <marek.safar@gmail.com>
Wed, 12 Jan 2011 09:25:18 +0000 (09:25 +0000)
mcs/errors/cs1607-2.cs [new file with mode: 0644]
mcs/mcs/assembly.cs
mcs/mcs/attribute.cs

diff --git a/mcs/errors/cs1607-2.cs b/mcs/errors/cs1607-2.cs
new file mode 100644 (file)
index 0000000..2d0c3de
--- /dev/null
@@ -0,0 +1,7 @@
+// CS1607: The version number `1.*' specified for `AssemblyFileVersion' is invalid
+// Line: 7
+// Compiler options: -warnaserror
+
+using System.Reflection;
+
+[assembly: AssemblyFileVersion ("1.*")]
index df1602b666d88035b6dfa3668f6f81bd91a66cb1..0a2f536bcd2e51e88866c588ed09ca4c35f81d4e 100644 (file)
@@ -214,7 +214,7 @@ namespace Mono.CSharp
                                if (value == null || value.Length == 0)
                                        return;
 
-                               var vinfo = IsValidAssemblyVersion (value);
+                               var vinfo = IsValidAssemblyVersion (value, true);
                                if (vinfo == null) {
                                        a.Error_AttributeEmitError (string.Format ("Specified version `{0}' is not valid", value));
                                        return;
@@ -336,8 +336,16 @@ namespace Mono.CSharp
                                }
                        } else if (a.Type == pa.RuntimeCompatibility) {
                                wrap_non_exception_throws_custom = true;
+                       } else if (a.Type == pa.AssemblyFileVersion) {
+                               string value = a.GetString ();
+                               if (string.IsNullOrEmpty (value) || IsValidAssemblyVersion (value, false) == null) {
+                                       Report.Warning (1607, 1, a.Location, "The version number `{0}' specified for `{1}' is invalid",
+                                               value, a.Name);
+                                       return;
+                               }
                        }
 
+
                        SetCustomAttribute (ctor, cdata);
                }
 
@@ -871,7 +879,7 @@ namespace Mono.CSharp
                        Report.Error (1548, "Error during assembly signing. " + text);
                }
 
-               static Version IsValidAssemblyVersion (string version)
+               static Version IsValidAssemblyVersion (string version, bool allowGenerated)
                {
                        string[] parts = version.Split ('.');
                        if (parts.Length < 1 || parts.Length > 4)
@@ -880,7 +888,7 @@ namespace Mono.CSharp
                        var values = new int[4];
                        for (int i = 0; i < parts.Length; ++i) {
                                if (!int.TryParse (parts[i], out values[i])) {
-                                       if (parts[i].Length == 1 && parts[i][0] == '*') {
+                                       if (parts[i].Length == 1 && parts[i][0] == '*' && allowGenerated) {
                                                if (i == 2) {
                                                        // Nothing can follow *
                                                        if (parts.Length > 3)
index 8aa4e32c09d4720f7aed22a39ebcf9d2fee29562..e0f5a137549cfc807b16ff732fefe022dba41c59 100644 (file)
@@ -1637,6 +1637,7 @@ namespace Mono.CSharp {
                public readonly PredefinedAttribute AssemblyVersion;
                public readonly PredefinedAttribute AssemblyAlgorithmId;
                public readonly PredefinedAttribute AssemblyFlags;
+               public readonly PredefinedAttribute AssemblyFileVersion;
                public readonly PredefinedAttribute ComImport;
                public readonly PredefinedAttribute CoClass;
                public readonly PredefinedAttribute AttributeUsage;
@@ -1690,6 +1691,7 @@ namespace Mono.CSharp {
                        AssemblyVersion = new PredefinedAttribute (module, "System.Reflection", "AssemblyVersionAttribute");
                        AssemblyAlgorithmId = new PredefinedAttribute (module, "System.Reflection", "AssemblyAlgorithmIdAttribute");
                        AssemblyFlags = new PredefinedAttribute (module, "System.Reflection", "AssemblyFlagsAttribute");
+                       AssemblyFileVersion = new PredefinedAttribute (module, "System.Reflection", "AssemblyFileVersionAttribute");
                        ComImport = new PredefinedAttribute (module, "System.Runtime.InteropServices", "ComImportAttribute");
                        CoClass = new PredefinedAttribute (module, "System.Runtime.InteropServices", "CoClassAttribute");
                        AttributeUsage = new PredefinedAttribute (module, "System", "AttributeUsageAttribute");