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

hudson.Util.loadFile() has a race condition

    XMLWordPrintable

Details

    Description

      Util.loadFile() first checks if the file exists via File.exists(). It then tries to open the file for reading. However, it is possible for the file to be deleted between the existence check and the file-open operation, in which case the method throws a FileNotFoundException rather than returning an empty string.

      Attachments

        Activity

          dtrebbien Daniel Trebbien added a comment - https://github.com/jenkinsci/jenkins/pull/3225
          oleg_nenashev Oleg Nenashev added a comment -

          The patch has been integrated towards 2.111

          oleg_nenashev Oleg Nenashev added a comment - The patch has been integrated towards 2.111

          Code changed in jenkins
          User: Daniel Trebbien
          Path:
          core/src/main/java/hudson/Util.java
          http://jenkins-ci.org/commit/jenkins/aa799e39ad904183d1da3105b8b3267c7348cd71
          Log:
          JENKINS-49971 Fix a race condition in Util.loadFile() (#3225)

          • Fix a race condition in Util.loadFile()

          If the file is deleted in between when its existence is checked and the
          file is opened for reading, then the method will fail to return an empty
          string.

          • Switch to using FileUtils.readFileToString()

          (cherry picked from commit aaae71af4bd2952efdc3462fde086faa6a604ee2)

          Compare: https://github.com/jenkinsci/jenkins/compare/115612bbf558...aa799e39ad90

          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Trebbien Path: core/src/main/java/hudson/Util.java http://jenkins-ci.org/commit/jenkins/aa799e39ad904183d1da3105b8b3267c7348cd71 Log: JENKINS-49971 Fix a race condition in Util.loadFile() (#3225) Fix a race condition in Util.loadFile() If the file is deleted in between when its existence is checked and the file is opened for reading, then the method will fail to return an empty string. Switch to using FileUtils.readFileToString() (cherry picked from commit aaae71af4bd2952efdc3462fde086faa6a604ee2) Compare: https://github.com/jenkinsci/jenkins/compare/115612bbf558...aa799e39ad90

          People

            Unassigned Unassigned
            dtrebbien Daniel Trebbien
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: