--- old/src/hotspot/share/runtime/os.cpp 2019-08-09 17:37:06.492826101 +0100 +++ new/src/hotspot/share/runtime/os.cpp 2019-08-09 17:37:05.788810321 +0100 @@ -1349,7 +1349,7 @@ for (int i = 0 ; i < count ; i++) { size_t len = strcspn(p, os::path_separator()); if (len > JVM_MAXPATHLEN) { - return NULL; + //return NULL; } // allocate the string and add terminator storage char* s = (char*)NEW_C_HEAP_ARRAY(char, len + 1, mtInternal); --- old/src/jdk.jdwp.agent/unix/native/libjdwp/linker_md.c 2019-08-09 17:37:07.516849054 +0100 +++ new/src/jdk.jdwp.agent/unix/native/libjdwp/linker_md.c 2019-08-09 17:37:07.000837488 +0100 @@ -34,6 +34,7 @@ #include #include +#include "util.h" #include "path_md.h" #ifdef __APPLE__ @@ -45,6 +46,7 @@ static void dll_build_name(char* buffer, size_t buflen, const char* paths, const char* fname) { char *path, *paths_copy, *next_token; + *buffer = '\0'; paths_copy = strdup(paths); if (paths_copy == NULL) { @@ -55,8 +57,11 @@ path = strtok_r(paths_copy, PATH_SEPARATOR, &next_token); while (path != NULL) { - snprintf(buffer, buflen, "%s/lib%s." LIB_SUFFIX, path, fname); - if (access(buffer, F_OK) == 0) { + size_t result_len = (size_t)snprintf(buffer, buflen, "%s/lib%s." LIB_SUFFIX, path, fname); + if (result_len >= buflen) { + EXIT_ERROR(JVMTI_ERROR_INVALID_LOCATION, "One or more of the library paths supplied to jdwp, " + "likely by sun.boot.library.path, is too long."); + } else if (access(buffer, F_OK) == 0) { break; } *buffer = '\0'; @@ -89,13 +94,11 @@ { const int pnamelen = pname ? strlen(pname) : 0; - *holder = '\0'; - // Quietly truncate on buffer overflow. Should be an error. - if (pnamelen + (int)strlen(fname) + 10 > holderlen) { - return; - } - if (pnamelen == 0) { + if (pnamelen + (int)strlen(fname) + 10 > holderlen) { + EXIT_ERROR(JVMTI_ERROR_INVALID_LOCATION, "One or more of the library paths supplied to jdwp, " + "likely by sun.boot.library.path, is too long."); + } (void)snprintf(holder, holderlen, "lib%s." LIB_SUFFIX, fname); } else { dll_build_name(holder, holderlen, pname, fname); --- old/src/jdk.jdwp.agent/windows/native/libjdwp/linker_md.c 2019-08-09 17:37:08.516871467 +0100 +++ new/src/jdk.jdwp.agent/windows/native/libjdwp/linker_md.c 2019-08-09 17:37:07.988859632 +0100 @@ -37,11 +37,13 @@ #include "sys.h" +#include "util.h" #include "path_md.h" static void dll_build_name(char* buffer, size_t buflen, const char* paths, const char* fname) { char *path, *paths_copy, *next_token; + *buffer = '\0'; paths_copy = strdup(paths); if (paths_copy == NULL) { @@ -52,8 +54,11 @@ path = strtok_s(paths_copy, PATH_SEPARATOR, &next_token); while (path != NULL) { - _snprintf(buffer, buflen, "%s\\%s.dll", path, fname); - if (_access(buffer, 0) == 0) { + size_t result_len = (size_t)_snprintf(buffer, buflen, "%s\\%s.dll", path, fname); + if (result_len >= buflen) { + EXIT_ERROR(JVMTI_ERROR_INVALID_LOCATION, "One or more of the library paths supplied to jdwp, " + "likely by sun.boot.library.path, is too long."); + } else if (_access(buffer, 0) == 0) { break; } *buffer = '\0'; @@ -107,13 +112,11 @@ { const int pnamelen = pname ? (int)strlen(pname) : 0; - *holder = '\0'; - /* Quietly truncates on buffer overflow. Should be an error. */ - if (pnamelen + (int)strlen(fname) + 10 > holderlen) { - return; - } - if (pnamelen == 0) { + if (pnamelen + (int)strlen(fname) + 10 > holderlen) { + EXIT_ERROR(JVMTI_ERROR_INVALID_LOCATION, "One or more of the library paths supplied to jdwp, " + "likely by sun.boot.library.path, is too long."); + } sprintf(holder, "%s.dll", fname); } else { dll_build_name(holder, holderlen, pname, fname);