mono_reflection_parse_type(): pointer and ref parse errors.
authorAleksey Kliger <aleksey@xamarin.com>
Tue, 6 Oct 2015 22:11:27 +0000 (18:11 -0400)
committerAleksey Kliger <aleksey@xamarin.com>
Tue, 6 Oct 2015 22:31:53 +0000 (18:31 -0400)
pointer to ref (A&*), array of ref (A&[]), generic instantiation of
ref (A&[int]), generic instantiation of pointer (A*[int]) are all parse errors.

mono/metadata/reflection.c

index 73dffddad6b08c62d04f7bfd08c49289a90124a3..fe82ab500726677d0614c5958a94249f97cc987f 100644 (file)
@@ -7424,7 +7424,7 @@ _mono_reflection_parse_type (char *name, char **endptr, gboolean is_recursed,
 {
        char *start, *p, *w, *last_point, *startn;
        int in_modifiers = 0;
-       int isbyref = 0, rank = 0;
+       int isbyref = 0, rank = 0, isptr = 0;
 
        start = p = w = name;
 
@@ -7496,20 +7496,27 @@ _mono_reflection_parse_type (char *name, char **endptr, gboolean is_recursed,
                        if (isbyref) /* only one level allowed by the spec */
                                return 0;
                        isbyref = 1;
+                       isptr = 0;
                        info->modifiers = g_list_append (info->modifiers, GUINT_TO_POINTER (0));
                        *p++ = 0;
                        break;
                case '*':
+                       if (isbyref) /* pointer to ref not okay */
+                               return 0;
                        info->modifiers = g_list_append (info->modifiers, GUINT_TO_POINTER (-1));
+                       isptr = 1;
                        *p++ = 0;
                        break;
                case '[':
+                       if (isbyref) /* array of ref and generic ref are not okay */
+                               return 0;
                        //Decide if it's an array of a generic argument list
                        *p++ = 0;
 
                        if (!*p) //XXX test
                                return 0;
                        if (*p  == ',' || *p == '*' || *p == ']') { //array
+                               isptr = 0;
                                rank = 1;
                                while (*p) {
                                        if (*p == ']')
@@ -7526,8 +7533,9 @@ _mono_reflection_parse_type (char *name, char **endptr, gboolean is_recursed,
                                        return 0;
                                info->modifiers = g_list_append (info->modifiers, GUINT_TO_POINTER (rank));
                        } else {
-                               if (rank) /* generic args after array spec*/ //XXX test
+                               if (rank || isptr) /* generic args after array spec or ptr*/ //XXX test
                                        return 0;
+                               isptr = 0;
                                info->type_arguments = g_ptr_array_new ();
                                while (*p) {
                                        MonoTypeNameParse *subinfo = g_new0 (MonoTypeNameParse, 1);