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

(process) Windows Process.exitValue() has poor error handling

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 6
    • core-libs
    • None
    • b15
    • generic
    • generic

      The implementation of exitValue() is not careful enough to check for errors.

      JNIEXPORT jint JNICALL
      Java_java_lang_ProcessImpl_exitValue(JNIEnv *env, jobject process)
      {
          jint exit_code;
          jboolean exc;
          jlong handle = JNU_GetFieldByName(env, &exc, process, "handle", "J").j;
          if (exc) {
              return 0;
          }

          GetExitCodeProcess((void *)handle, &exit_code);
          if (exit_code == STILL_ACTIVE) {
      JNU_ThrowByName(env, "java/lang/IllegalThreadStateException",
      "process has not exited");
      return -1;
          }
          return exit_code;
      }

      What happens if GetExitCodeProcess fails?
      In this case there should be an exception thrown with a human-readable
      error description.
      Also, in this case exit_code may never be initialized, with the result that the
      returned value is whatever random garbage was on the stack at the point of call.

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: