1 /*
2 * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 /*-
27 * Verify that the code within a method block doesn't exploit any
28 * security holes.
29 */
30 /*
31 Exported function:
32
33 jboolean
34 VerifyClass(JNIEnv *env, jclass cb, char *message_buffer,
35 jint buffer_length)
36 jboolean
37 VerifyClassForMajorVersion(JNIEnv *env, jclass cb, char *message_buffer,
38 jint buffer_length, jint major_version)
39
40 This file now only uses the standard JNI and the following VM functions
41 exported in jvm.h:
42
43 JVM_FindClassFromClass
44 JVM_IsInterface
45 JVM_GetClassNameUTF
46 JVM_GetClassCPEntriesCount
47 JVM_GetClassCPTypes
48 JVM_GetClassFieldsCount
49 JVM_GetClassMethodsCount
50
51 JVM_GetFieldIxModifiers
52
53 JVM_GetMethodIxModifiers
54 JVM_GetMethodIxExceptionTableLength
55 JVM_GetMethodIxLocalsCount
56 JVM_GetMethodIxArgsSize
891 #ifdef DEBUG
892 GlobalContext = 0;
893 #endif
894
895 if (context->exceptions)
896 free(context->exceptions);
897
898 if (context->constant_types)
899 free(context->constant_types);
900
901 if (context->superclasses)
902 free(context->superclasses);
903
904 #ifdef DEBUG
905 /* Make sure all global refs created in the verifier are freed */
906 assert(context->n_globalrefs == 0);
907 #endif
908
909 CCdestroy(context); /* destroy heap */
910 return result;
911 }
912
913 #define OLD_FORMAT_MAX_MAJOR_VERSION 48
914
915 JNIEXPORT jboolean
916 VerifyClass(JNIEnv *env, jclass cb, char *buffer, jint len)
917 {
918 static int warned = 0;
919 if (!warned) {
920 jio_fprintf(stdout, "Warning! An old version of jvm is used. This is not supported.\n");
921 warned = 1;
922 }
923 return VerifyClassForMajorVersion(env, cb, buffer, len,
924 OLD_FORMAT_MAX_MAJOR_VERSION);
925 }
926
927 static void
928 verify_field(context_type *context, jclass cb, int field_index)
929 {
930 JNIEnv *env = context->env;
931 int access_bits = JVM_GetFieldIxModifiers(env, cb, field_index);
932 context->field_index = field_index;
933
934 if ( ((access_bits & JVM_ACC_PUBLIC) != 0) &&
935 ((access_bits & (JVM_ACC_PRIVATE | JVM_ACC_PROTECTED)) != 0)) {
936 CCerror(context, "Inconsistent access bits.");
937 }
938 context->field_index = -1;
939 }
940
941
942 /**
943 * We read all of the class's methods' code because it is possible that
944 * the verification of one method could resulting in linking further
|
1 /*
2 * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 /*-
27 * Verify that the code within a method block doesn't exploit any
28 * security holes.
29 */
30 /*
31 Exported function:
32
33 jboolean
34 VerifyClassForMajorVersion(JNIEnv *env, jclass cb, char *message_buffer,
35 jint buffer_length, jint major_version)
36
37 This file now only uses the standard JNI and the following VM functions
38 exported in jvm.h:
39
40 JVM_FindClassFromClass
41 JVM_IsInterface
42 JVM_GetClassNameUTF
43 JVM_GetClassCPEntriesCount
44 JVM_GetClassCPTypes
45 JVM_GetClassFieldsCount
46 JVM_GetClassMethodsCount
47
48 JVM_GetFieldIxModifiers
49
50 JVM_GetMethodIxModifiers
51 JVM_GetMethodIxExceptionTableLength
52 JVM_GetMethodIxLocalsCount
53 JVM_GetMethodIxArgsSize
888 #ifdef DEBUG
889 GlobalContext = 0;
890 #endif
891
892 if (context->exceptions)
893 free(context->exceptions);
894
895 if (context->constant_types)
896 free(context->constant_types);
897
898 if (context->superclasses)
899 free(context->superclasses);
900
901 #ifdef DEBUG
902 /* Make sure all global refs created in the verifier are freed */
903 assert(context->n_globalrefs == 0);
904 #endif
905
906 CCdestroy(context); /* destroy heap */
907 return result;
908 }
909
910 static void
911 verify_field(context_type *context, jclass cb, int field_index)
912 {
913 JNIEnv *env = context->env;
914 int access_bits = JVM_GetFieldIxModifiers(env, cb, field_index);
915 context->field_index = field_index;
916
917 if ( ((access_bits & JVM_ACC_PUBLIC) != 0) &&
918 ((access_bits & (JVM_ACC_PRIVATE | JVM_ACC_PROTECTED)) != 0)) {
919 CCerror(context, "Inconsistent access bits.");
920 }
921 context->field_index = -1;
922 }
923
924
925 /**
926 * We read all of the class's methods' code because it is possible that
927 * the verification of one method could resulting in linking further
|