8186766: UnixNativeDispatcher::readlink() may truncate overlong paths
authorbpb
Fri, 03 Aug 2018 12:45:18 -0700
changeset 51309 13e2e64337be
parent 51308 acf02a6f369e
child 51310 a694574b2def
child 51903 f91e995f6d5c
8186766: UnixNativeDispatcher::readlink() may truncate overlong paths Reviewed-by: alanb
src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
--- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c	Fri Aug 03 09:42:57 2018 -0700
+++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c	Fri Aug 03 12:45:18 2018 -0700
@@ -875,7 +875,10 @@
     } 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);