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

Java_java_lang_ProcessEnvironment_environ is not thread safe

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8, 11, 16, 17, 18
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:
      None

      Description

      The native implementation of ProcessEnvironment.environ[1] iterates over the global `environ` variable twice, expecting it to be the same length in both iterations. However, any interleaving call to setenv/putenv could change the contents. One such call is from libjli.dylib on macOS, which sets an environment variable[2] after the JVM has been booted.

      We see this with some frequency during GraalVM testing with stack traces such as:

      Caused by: java.lang.ArrayIndexOutOfBoundsException: 145
              at java.lang.ProcessEnvironment.environ(java.base@11.0.10/Native Method)
              at java.lang.ProcessEnvironment.<clinit>(java.base@11.0.10/ProcessEnvironment.java:70)
              at java.lang.System.getenv(java.base@11.0.10/System.java:1049)
              at org.graalvm.compiler.options.ModuleSupport.<clinit>(jdk.internal.vm.compiler/ModuleSupport.java:31)

      [1] https://github.com/openjdk/jdk/blob/739769c8fc4b496f08a92225a12d07414537b6c0/src/java.base/unix/native/libjava/ProcessEnvironment_md.c#L50
      [2] https://github.com/openjdk/jdk/blob/739769c8fc/src/java.base/macosx/native/libjli/java_md_macosx.m#L862

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rriggs Roger Riggs
              Reporter:
              dnsimon Douglas Simon
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated: