src/java.base/share/native/libverify/check_format.c
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.base/share/native/libverify/check_format.c@3317bb8137f4
child 54053 ab7c5483df44
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1090
diff changeset
     2
 * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1090
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1090
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1090
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1090
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1090
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <setjmp.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
typedef unsigned short unicode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
skip_over_fieldname(char *name, jboolean slash_okay,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
                    unsigned int len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
skip_over_field_signature(char *name, jboolean void_okay,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                          unsigned int len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Return non-zero if the character is a valid in JVM class name, zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * otherwise.  The only characters currently disallowed from JVM class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * names are given in the table below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Character    Hex     Decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * '.'          0x2e    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * '/'          0x2f    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * ';'          0x3b    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * '['          0x5b    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * (Method names have further restrictions dealing with the '<' and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * '>' characters.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
static int isJvmIdentifier(unicode ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  if( ch > 91 || ch < 46 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    return 1;   /* Lowercase ASCII letters are > 91 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  else { /* 46 <= ch <= 91 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    if (ch <= 90 && ch >= 60) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
      return 1; /* Uppercase ASCII recognized here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    } else { /* ch == 91 || 46 <= ch <= 59 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
      if (ch == 91 || ch == 59 || ch <= 47)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
static unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
next_utf2unicode(char **utfstring_ptr, int * valid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    unsigned char *ptr = (unsigned char *)(*utfstring_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    unsigned char ch, ch2, ch3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    int length = 1;             /* default length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    unicode result = 0x80;      /* default bad result; */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    *valid = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    switch ((ch = ptr[0]) >> 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            result = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        case 0x8: case 0x9: case 0xA: case 0xB: case 0xF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            /* Shouldn't happen. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            *valid = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        case 0xC: case 0xD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            /* 110xxxxx  10xxxxxx */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            if (((ch2 = ptr[1]) & 0xC0) == 0x80) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                unsigned char high_five = ch & 0x1F;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                unsigned char low_six = ch2 & 0x3F;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                result = (high_five << 6) + low_six;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                length = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        case 0xE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            /* 1110xxxx 10xxxxxx 10xxxxxx */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            if (((ch2 = ptr[1]) & 0xC0) == 0x80) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                if (((ch3 = ptr[2]) & 0xC0) == 0x80) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    unsigned char high_four = ch & 0x0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    unsigned char mid_six = ch2 & 0x3f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    unsigned char low_six = ch3 & 0x3f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    result = (((high_four << 6) + mid_six) << 6) + low_six;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    length = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    length = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        } /* end of switch */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    *utfstring_ptr = (char *)(ptr + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
/* Take pointer to a string.  Skip over the longest part of the string that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * could be taken as a fieldname.  Allow '/' if slash_okay is JNI_TRUE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * Return a pointer to just past the fieldname.  Return NULL if no fieldname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * at all was found, or in the case of slash_okay being true, we saw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * consecutive slashes (meaning we were looking for a qualified path but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * found something that was badly-formed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
skip_over_fieldname(char *name, jboolean slash_okay,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    unsigned int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    char *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    unicode ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    unicode last_ch = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    int valid = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /* last_ch == 0 implies we are looking at the first char. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    for (p = name; p != name + length; last_ch = ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        char *old_p = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        ch = *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (ch < 128) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            if (isJvmIdentifier(ch)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            char *tmp_p = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            ch = next_utf2unicode(&tmp_p, &valid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (valid == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
              return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            p = tmp_p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            if (isJvmIdentifier(ch)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (slash_okay && ch == '/' && last_ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            if (last_ch == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                return 0;       /* Don't permit consecutive slashes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        } else if (ch == '_' || ch == '$') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return last_ch ? old_p : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    return last_ch ? p : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
/* Take pointer to a string.  Skip over the longest part of the string that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * could be taken as a field signature.  Allow "void" if void_okay.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * Return a pointer to just past the signature.  Return NULL if no legal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * signature is found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
skip_over_field_signature(char *name, jboolean void_okay,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                          unsigned int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    unsigned int array_dim = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    for (;length > 0;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        switch (name[0]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            case JVM_SIGNATURE_VOID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                if (!void_okay) return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                /* FALL THROUGH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            case JVM_SIGNATURE_BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            case JVM_SIGNATURE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            case JVM_SIGNATURE_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            case JVM_SIGNATURE_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            case JVM_SIGNATURE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            case JVM_SIGNATURE_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            case JVM_SIGNATURE_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            case JVM_SIGNATURE_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                return name + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            case JVM_SIGNATURE_CLASS: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                /* Skip over the classname, if one is there. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                char *p =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    skip_over_fieldname(name + 1, JNI_TRUE, --length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                /* The next character better be a semicolon. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                if (p && p - name - 1 > 0 && p[0] == ';')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    return p + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            case JVM_SIGNATURE_ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                array_dim++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                /* JVMS 2nd ed. 4.10 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                /*   The number of dimensions in an array is limited to 255 ... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                if (array_dim > 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                /* The rest of what's there better be a legal signature.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                name++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                length--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                void_okay = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
/* Used in java/lang/Class.c */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
/* Determine if the specified name is legal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * UTF name for a classname.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * Note that this routine expects the internal form of qualified classes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * the dots should have been replaced by slashes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
JNIEXPORT jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
VerifyClassname(char *name, jboolean allowArrayClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    unsigned int length = strlen(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    char *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    if (length > 0 && name[0] == JVM_SIGNATURE_ARRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (!allowArrayClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            /* Everything that's left better be a field signature */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            p = skip_over_field_signature(name, JNI_FALSE, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        /* skip over the fieldname.  Slashes are okay */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        p = skip_over_fieldname(name, JNI_TRUE, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
1090
c5805b1672a6 6732421: Removed old javavm and Classic VM files from the jdk7 sources
ohair
parents: 2
diff changeset
   249
    return (p != 0 && p - name == (ptrdiff_t)length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 * Translates '.' to '/'.  Returns JNI_TRUE is any / were present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
JNIEXPORT jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
VerifyFixClassname(char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    char *p = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    jboolean slashesFound = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    int valid = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    while (valid != 0 && *p != '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (*p == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            slashesFound = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        } else if (*p == '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            *p++ = '/';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            next_utf2unicode(&p, &valid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    return slashesFound && valid != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
}