Browse Source

[sre] ModuleBuilder.DefineUnitializedData argument checks

1. Fix off by one in size check.
  Largest usable size is 0x3effff, first unusable size is 0x3f0000
  (Also change order of ArgumentException arguments - param name is second.
   Set it to null because of misguided CoreFX SRE test that expects a null name)
2. Check for empty string field name.
Aleksey Kliger 8 years ago
parent
commit
39b2b769d5
1 changed files with 11 additions and 4 deletions
  1. 11 4
      mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs

+ 11 - 4
mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs

@@ -159,21 +159,28 @@ namespace System.Reflection.Emit {
 			if (data == null)
 				throw new ArgumentNullException ("data");
 
-			FieldBuilder fb = DefineUninitializedData (name, data.Length, 
-													   attributes | FieldAttributes.HasFieldRVA);
+			var maskedAttributes = attributes & ~FieldAttributes.ReservedMask;
+			FieldBuilder fb = DefineDataImpl (name, data.Length, maskedAttributes | FieldAttributes.HasFieldRVA);
 			fb.SetRVAData (data);
 
 			return fb;
 		}
 
 		public FieldBuilder DefineUninitializedData (string name, int size, FieldAttributes attributes)
+		{
+			return DefineDataImpl (name, size, attributes & ~FieldAttributes.ReservedMask);
+		}
+
+		private FieldBuilder DefineDataImpl (string name, int size, FieldAttributes attributes)
 		{
 			if (name == null)
 				throw new ArgumentNullException ("name");
+			if (name == String.Empty)
+				throw new ArgumentException ("name cannot be empty", "name");
 			if (global_type_created != null)
 				throw new InvalidOperationException ("global fields already created");
-			if ((size <= 0) || (size > 0x3f0000))
-				throw new ArgumentException ("size", "Data size must be > 0 and < 0x3f0000");
+			if ((size <= 0) || (size >= 0x3f0000))
+				throw new ArgumentException ("Data size must be > 0 and < 0x3f0000", null as string);
 
 			CreateGlobalType ();