Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4928468

Need to audit JNI code for invalid values of env

XMLWordPrintable

    • x86
    • windows_xp

      In fixing bugid 4898868 it was discovered that AWT sometimes does not check
      for null values of env at the beginning of JNI calls. E.g. in
      /src/win32/native/sun/windows/awt_new.cpp the code read:

      int
      NewHandler::handler(size_t) {
          JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
          if (env->EnsureLocalCapacity(1) < 0) {
              return 0;
          }

      and the pointer "env" was dereferenced without checking to see if it was valid.

      The doc for JNU_GetEnv() in src/share/native/common/jni_util.h reads:

      /*
        * Check if the current thread is attached to the VM, and returns
        * the JNIEnv of the specified version if the thread is attached.
        *
        * If the current thread is not attached, this function returns 0.
        *
        * If the current thread is attached, this function returns the
        * JNI environment, or returns (void *)JNI_ERR if the specified
        * version is not suppored.
        */
      JNIEXPORT void * JNICALL
      JNU_GetEnv(JavaVM *vm, jint version);

      We should audit the AWT JNI code and handle error conditions such as this one.
      I imagine we should do it for the unix native code as well as windows.

            son Oleg Sukhodolsky (Inactive)
            ehawkessunw Eric Hawkes (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: