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

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 7
    • Affects Version/s: 6
    • Component/s: 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.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: