8186766: UnixNativeDispatcher::readlink() may truncate overlong paths
Reviewed-by: alanb
--- 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);