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

(fs) UnixPath::toRealPath needs additional permissions when running with SM (macOS)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 21
    • 20.0.1
    • core-libs
    • b25
    • generic
    • os_x
    • Verified

      ADDITIONAL SYSTEM INFORMATION :
      MacOSX, JDK 20

      A DESCRIPTION OF THE PROBLEM :
      The fix addressing JDK-8295753 causes reproducible AccessControlException on the '/' folder in MacOSX. It seems the fix now requires granting full read rights to all folders on the path to a resource, something that wasn't required before.

      REGRESSION : Last worked in version 17.0.7

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run provided source with enabled security manager.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Hello World!
      /private/tmp/hello.txt
      ACTUAL -
      Hello World!
      Exception in thread "main" java.security.AccessControlException: access denied ("java.io.FilePermission" "/" "read")

      ---------- BEGIN SOURCE ----------
      Policy:
      grant {
          permission java.io.FilePermission "/private/tmp", "read,write";
          permission java.io.FilePermission "/private/tmp/-", "read,write,delete";
      };

      Reproducer:
      public static void main(String[] args) throws Exception {
              // Works
              Files.writeString(Paths.get("/private/tmp/hello.txt"), "Hello World!");
              System.out.println(Files.readString(Paths.get("/private/tmp/hello.txt")));

              // Exception
              System.out.println(Paths.get("/private/tmp/hello.txt").toRealPath(LinkOption.NOFOLLOW_LINKS));
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Grant read access to all folders for a resource on the way to the root
      or
      Use JDK < 20
      or
      Don't use toRealPath.

      FREQUENCY : always


            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: