Closed headius closed 3 years ago
Regarding the native encoding of the path into the buffer, questioned in @fweimer-rh's review... I believe this is the correct way.
defaultCharset
for the current JVM is based on the file.encoding
property:
https://github.com/openjdk/jdk/blob/7fc8540907e8e7483ad5729ea416167810aa8747/src/java.base/share/classes/java/nio/charset/Charset.java#L609-L622file.encoding
property is set using the platform locale:
https://github.com/openjdk/jdk/blob/bebfae48e3f1643f2456d680d170dcc22f7231bf/src/java.base/unix/native/libjava/java_props_md.c#L432
https://github.com/openjdk/jdk/blob/bebfae48e3f1643f2456d680d170dcc22f7231bf/src/java.base/unix/native/libjava/java_props_md.c#L106sun.jnu.encoding
:
https://github.com/openjdk/jdk/blob/master/src/java.base/unix/native/libjava/UnixFileSystem_md.c#L97
https://github.com/openjdk/jdk/blob/a1c942c02b65a7fc2a837d2bb43fa134dadcad11/src/java.base/share/native/libjava/jni_util.c#L910
https://github.com/openjdk/jdk/blob/a1c942c02b65a7fc2a837d2bb43fa134dadcad11/src/java.base/share/native/libjava/jni_util.c#L727-L792
https://github.com/openjdk/jdk/blob/739769c8fc4b496f08a92225a12d07414537b6c0/src/java.base/share/native/libjava/System.c#L121sun.jnu.encoding
property is set to the same value as file.encoding
, except on MacOS where they are both hardcoded to UTF-8.The null terminator length is debateable but I'm pretty sure the Java code here for encoding the path matches what the equivalent JNI-based filesystem APIs would do.
Works around systems that haven't fixed CVE-2014-4043.
See https://bugzilla.redhat.com/show_bug.cgi?id=1983750