Fwd: [12] 8186766: (fs) UnixNativeDispatcher::readlink() may truncate overlong paths

Brian Burkhalter brian.burkhalter at oracle.com
Wed Aug 1 14:50:20 UTC 2018


https://bugs.openjdk.java.net/browse/JDK-8186766

Diff included below. Some PATH_MAX-related content previously in this issue was excised and will be dealt with under a different issue.

Thanks,

Brian

--- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
+++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
@@ -864,29 +864,32 @@
 Java_sun_nio_fs_UnixNativeDispatcher_readlink0(JNIEnv* env, jclass this,
     jlong pathAddress)
 {
     jbyteArray result = NULL;
     char target[PATH_MAX+1];
     const char* path = (const char*)jlong_to_ptr(pathAddress);
 
     /* EINTR not listed as a possible error */
     int n = readlink(path, target, sizeof(target));
     if (n == -1) {
         throwUnixException(env, errno);
     } else {
         jsize len;
         if (n == sizeof(target)) {
-            n--;
+            /* Traditionally readlink(2) should not return more than */
+            /* PATH_MAX bytes (no terminating null byte is appended). */
+            throwUnixException(env, ENAMETOOLONG);
+            return NULL;
         }
         target[n] = '\0';
         len = (jsize)strlen(target);
         result = (*env)->NewByteArray(env, len);
         if (result != NULL) {
             (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)target);
         }
     }
     return result;
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20180801/b921cc5f/attachment.html>


More information about the nio-dev mailing list