Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-59580

NPE in OSProcess#hasMatchingEnvVars on Windows

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • core
    • Windows, Jenkins Core master from GitHub
    • 2.199

      Reproducing code:

              OUTER:
              while (true) {
                  for (OSProcess proc : ProcessTree.get()) {
                      if (proc.hasMatchingEnvVars(Collections.singletonMap("foo", "bar"))) { //-------- fails with NPE
                          break OUTER;
                      }
                  }
              }

      Analysis:
      1. OSProcess#hasMatchingEnvVars assumes that OSProcess#getEnvironmentVariables never returns null (and its Javadoc says so).
      2. There's a time frame between ProcessTree.get() and call to getEnvironmentVariables
      3. If proccess exits during this timeframe, an exception is thrown by org.jvnet.winp.WinProcess#getEnvironmentVariables, propagated through WindowsOSProcess#getEnvironmentVariables2, then caught in WindowsOSProcess#getEnvironmentVariables
      4. And finally, WindowsOSProcess#getEnvironmentVariables returns null, thus violating contract from superclass Javadoc.

          [JENKINS-59580] NPE in OSProcess#hasMatchingEnvVars on Windows

          Marat Radchenko created issue -
          Marat Radchenko made changes -
          Remote Link New: This issue links to "PR#4231 (Web Link)" [ 23731 ]
          Marat Radchenko made changes -
          Description Original: Reproducing code:

          {code} OUTER:
                  while (true) {
                      for (OSProcess proc : ProcessTree.get()) {
                          if (proc.hasMatchingEnvVars(Collections.singletonMap("foo", "bar"))) {
                              break OUTER;
                          }
                      }
                  }{code}

          Analysis:
          1. {{OSProcess#hasMatchingEnvVars}} assumes that {{OSProcess#getEnvironmentVariables}} never returns null (and its Javadoc says so).
          2. There's a time frame between {{ProcessTree.get()}} and call to {{getEnvironmentVariables}}
          3. If proccess exits during this timeframe, an exception is thrown by {{org.jvnet.winp.WinProcess#getEnvironmentVariables}}, propagated through {{WindowsOSProcess#getEnvironmentVariables2}}, then caught in {{WindowsOSProcess#getEnvironmentVariables}}
          4. And finally, {{WindowsOSProcess#getEnvironmentVariables}} returns null, thus violating contract from superclass Javadoc.
          New: Reproducing code:

          {code} OUTER:
                  while (true) {
                      for (OSProcess proc : ProcessTree.get()) {
                          if (proc.hasMatchingEnvVars(Collections.singletonMap("foo", "bar"))) { //-------- fails with NPE
                              break OUTER;
                          }
                      }
                  }{code}

          Analysis:
          1. {{OSProcess#hasMatchingEnvVars}} assumes that {{OSProcess#getEnvironmentVariables}} never returns null (and its Javadoc says so).
          2. There's a time frame between {{ProcessTree.get()}} and call to {{getEnvironmentVariables}}
          3. If proccess exits during this timeframe, an exception is thrown by {{org.jvnet.winp.WinProcess#getEnvironmentVariables}}, propagated through {{WindowsOSProcess#getEnvironmentVariables2}}, then caught in {{WindowsOSProcess#getEnvironmentVariables}}
          4. And finally, {{WindowsOSProcess#getEnvironmentVariables}} returns null, thus violating contract from superclass Javadoc.
          Marat Radchenko made changes -
          Released As New: 2.199
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Fixed but Unreleased [ 10203 ]
          Daniel Beck made changes -
          Status Original: Fixed but Unreleased [ 10203 ] New: Closed [ 6 ]
          Oleg Nenashev made changes -
          Labels New: lts-candidate
          Oliver Gondža made changes -
          Labels Original: lts-candidate New: 2.190.2-fixed

            Unassigned Unassigned
            slonopotamusorama Marat Radchenko
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: