From 0c61eb1b122b8d98e2e3ad3f443c97bd21e471b2 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Mon, 9 Oct 2017 19:15:41 -0400 Subject: [reflection] Throw TLE for Type.GetType("", true) (Fixes #59664) In the C parser check for empty at the outset. In the managed parser, copy an empty string component to the built-up TypeSpec and handle it in the Type.GetType (..., asmResolver, typeResolver) implementation --- mcs/class/corlib/ReferenceSources/Type.cs | 21 +++++++++------------ mcs/class/corlib/System/TypeSpec.cs | 4 +++- 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'mcs') diff --git a/mcs/class/corlib/ReferenceSources/Type.cs b/mcs/class/corlib/ReferenceSources/Type.cs index a77d734c366..664782b1706 100644 --- a/mcs/class/corlib/ReferenceSources/Type.cs +++ b/mcs/class/corlib/ReferenceSources/Type.cs @@ -43,22 +43,12 @@ namespace System public static Type GetType(string typeName) { - if (typeName == null) - throw new ArgumentNullException ("TypeName"); - - return internal_from_name (typeName, false, false); + return GetType (typeName, false, false); } public static Type GetType(string typeName, bool throwOnError) { - if (typeName == null) - throw new ArgumentNullException ("TypeName"); - - Type type = internal_from_name (typeName, throwOnError, false); - if (throwOnError && type == null) - throw new TypeLoadException ("Error loading '" + typeName + "'"); - - return type; + return GetType (typeName, throwOnError, false); } public static Type GetType(string typeName, bool throwOnError, bool ignoreCase) @@ -66,6 +56,11 @@ namespace System if (typeName == null) throw new ArgumentNullException ("TypeName"); + if (typeName == String.Empty) + if (throwOnError) + throw new TypeLoadException ("A null or zero length string does not represent a valid Type."); + else + return null; Type t = internal_from_name (typeName, throwOnError, ignoreCase); if (throwOnError && t == null) throw new TypeLoadException ("Error loading '" + typeName + "'"); @@ -82,6 +77,8 @@ namespace System { if (typeName == null) throw new ArgumentNullException ("typeName"); + if (typeName == String.Empty && throwIfNotFound) + throw new TypeLoadException ("A null or zero length string does not represent a valid Type"); int idx = typeName.IndexOf (','); if (idx < 0 || idx == 0 || idx == typeName.Length - 1) throw new ArgumentException ("Assembly qualifed type name is required", "typeName"); diff --git a/mcs/class/corlib/System/TypeSpec.cs b/mcs/class/corlib/System/TypeSpec.cs index f233bec088e..4436a77810f 100644 --- a/mcs/class/corlib/System/TypeSpec.cs +++ b/mcs/class/corlib/System/TypeSpec.cs @@ -455,7 +455,9 @@ namespace System { } if (name_start < pos) - data.AddName (name.Substring (name_start, pos - name_start)); + data.AddName (name.Substring (name_start, pos - name_start)); + else if (name_start == pos) + data.AddName (String.Empty); if (in_modifiers) { for (; pos < name.Length; ++pos) { -- cgit v1.2.3