X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=vm%2FJni.cpp;h=0e77fab3e6b2f89f8e52561cb66530e635b4fe2f;hb=c5d0614f778e0f26db913fdc7320f08e9417e984;hp=d91eb9c5a6385b8e1a6fd0cd13021680be4a9da7;hpb=ae77d6b60ffa091d4d72597d2dd244cd6758e18f;p=android-x86%2Fdalvik.git diff --git a/vm/Jni.cpp b/vm/Jni.cpp index d91eb9c5a..0e77fab3e 100644 --- a/vm/Jni.cpp +++ b/vm/Jni.cpp @@ -285,6 +285,11 @@ void dvmJniShutdown() { dvmClearReferenceTable(&gDvm.jniPinRefTable); } +bool dvmIsBadJniVersion(int version) { + // We don't support JNI_VERSION_1_1. These are the only other valid versions. + return version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4 && version != JNI_VERSION_1_6; +} + /* * Find the JNIEnv associated with the current thread. * @@ -2814,6 +2819,13 @@ static jint attachThread(JavaVM* vm, JNIEnv** p_env, void* thr_args, bool isDaem argsCopy.name = NULL; argsCopy.group = (jobject) dvmGetMainThreadGroup(); } else { + if (dvmIsBadJniVersion(args->version)) { + ALOGE("Bad JNI version passed to %s: %d", + (isDaemon ? "AttachCurrentThreadAsDaemon" : "AttachCurrentThread"), + args->version); + return JNI_EVERSION; + } + argsCopy.version = args->version; argsCopy.name = args->name; if (args->group != NULL) { @@ -2892,7 +2904,10 @@ static jint DetachCurrentThread(JavaVM* vm) { static jint GetEnv(JavaVM* vm, void** env, jint version) { Thread* self = dvmThreadSelf(); - if (version < JNI_VERSION_1_1 || version > JNI_VERSION_1_6) { + // GetEnv also accepts JNI_VERSION_1_1, but always returns a JNIEnv* + // corresponding to the most current supported JNI version. + if (dvmIsBadJniVersion(version) && version != JNI_VERSION_1_1) { + ALOGE("Bad JNI version passed to GetEnv: %d", version); return JNI_EVERSION; } @@ -3408,7 +3423,8 @@ jint JNI_GetCreatedJavaVMs(JavaVM** vmBuf, jsize bufLen, jsize* nVMs) { */ jint JNI_CreateJavaVM(JavaVM** p_vm, JNIEnv** p_env, void* vm_args) { const JavaVMInitArgs* args = (JavaVMInitArgs*) vm_args; - if (args->version < JNI_VERSION_1_2) { + if (dvmIsBadJniVersion(args->version)) { + ALOGE("Bad JNI version passed to CreateJavaVM: %d", args->version); return JNI_EVERSION; }