< prev index next >
src/jdk.jdwp.agent/unix/native/libjdwp/linker_md.c
Print this page
@@ -32,10 +32,11 @@
#include <dlfcn.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include "util.h"
#include "path_md.h"
#ifdef __APPLE__
#define LIB_SUFFIX "dylib"
#else
@@ -43,22 +44,26 @@
#endif
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) {
return;
}
next_token = NULL;
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';
path = strtok_r(NULL, PATH_SEPARATOR, &next_token);
}
@@ -87,17 +92,15 @@
dbgsysBuildLibName(char *holder, int holderlen, const char *pname,
const char *fname)
{
const int pnamelen = pname ? strlen(pname) : 0;
- *holder = '\0';
- // Quietly truncate on buffer overflow. Should be an error.
+ if (pnamelen == 0) {
if (pnamelen + (int)strlen(fname) + 10 > holderlen) {
- return;
+ 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.");
}
-
- if (pnamelen == 0) {
(void)snprintf(holder, holderlen, "lib%s." LIB_SUFFIX, fname);
} else {
dll_build_name(holder, holderlen, pname, fname);
}
}
< prev index next >