changeset 51309:13e2e64337be

8186766: UnixNativeDispatcher::readlink() may truncate overlong paths Reviewed-by: alanb
author bpb
date Fri, 03 Aug 2018 12:45:18 -0700
parents acf02a6f369e
children a694574b2def f91e995f6d5c
files src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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);