回复:RFR: 8194154 patch for crash at File.getCanonicalPath()

Wenqian Pei wenqian.peiwq at alibaba-inc.com
Wed Dec 27 06:44:14 UTC 2017


Sorry, the patch and test is below:

diff -r 777356696811 src/java.base/unix/classes/java/io/UnixFileSystem.java
--- a/src/java.base/unix/classes/java/io/UnixFileSystem.java    Fri Sep 08 18:24:17 2017 +0000
+++ b/src/java.base/unix/classes/java/io/UnixFileSystem.java    Mon Dec 25 16:48:36 2017 +0800
@@ -100,10 +100,10 @@
         if (child.equals("")) return parent;
         if (child.charAt(0) == '/') {
             if (parent.equals("/")) return child;
-            return parent + child;
+            return normalize(parent + child);
         }
         if (parent.equals("/")) return parent + child;
-        return parent + '/' + child;
+        return normalize(parent + '/' + child);
     }
 
     public String getDefaultParent() {
diff -r 777356696811 test/java/io/File/GetCanonicalPath.java
--- a/test/java/io/File/GetCanonicalPath.java   Fri Sep 08 18:24:17 2017 +0000
+++ b/test/java/io/File/GetCanonicalPath.java   Mon Dec 25 16:48:36 2017 +0800
@@ -23,20 +23,35 @@
 
 /* @test
    @bug 4899022
+   @library /lib/testlibrary
+   @run main/othervm GetCanonicalPath 
    @summary Look for erroneous representation of drive letter
  */
 
 import java.io.*;
+import java.lang.reflect.Field;
+import java.util.Properties;
 
 public class GetCanonicalPath {
     public static void main(String[] args) throws Exception {
         if (File.separatorChar == '\\') {
             testDriveLetter();
         }
+        String osName = System.getProperty("os.name");
+        if (osName.startsWith("Linux")) {
+            testDuplicateSeparators();
+        }
     }
     private static void testDriveLetter() throws Exception {
         String path = new File("c:/").getCanonicalPath();
         if (path.length() > 3)
             throw new RuntimeException("Drive letter incorrectly represented");
     }
+    private static void testDuplicateSeparators() throws Exception {
+        Field f = System.class.getDeclaredField("props");
+        f.setAccessible(true);
+        Properties p = (Properties) f.get(null);
+        p.setProperty("user.dir", "/home/a/b/c/");
+        System.out.println(new File("./a").getCanonicalPath());
+   }
 } 
ps: only test on Linux :)
------------------------------------------------------------------发件人:David Holmes <david.holmes at oracle.com>发送时间:2017年12月27日(星期三) 14:14收件人:裴文谦(右席) <wenqian.peiwq at alibaba-inc.com>; core-libs-dev <core-libs-dev at openjdk.java.net>抄 送:陆传胜(传胜) <chuansheng.lcs at alipay.com>; 李三红(三红) <sanhong.lsh at alibaba-inc.com>主 题:Re: RFR: 8194154 patch for crash at File.getCanonicalPath()
Hi,

Attachments get stripped (usually). You'll need to include it inline.

Cheers,
David

On 25/12/2017 7:40 PM, Wenqian Pei wrote:
> 
> Hi:
> 
> Bug: https://bugs.openjdk.java.net/browse/JDK-8194154
> 
> We found that if user defines -Duser.dir like "/home/a/b/c/", jvm will crash at File.getCanonicalPath() in java process bootstrap (before invoking user's java code). The native implematation of canonicalize_md.c:collapsible(char *names) has problem in processing double '/', parameter 'names' need normalized before JNI_CALL.
> 
> This patch normalize parameters before call canonicalize0() in this call path
> 
> Patch and test are in mailbox attachments.
> 
> Can I please have a review for this patch?
> 
> 
> Thanks
> 
> 
> Wenqian Pei
> 


More information about the core-libs-dev mailing list