8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
Reviewed-by: alanb, sspitsyn
This commit is contained in:
parent
7d45058eaa
commit
bce70c8f7b
@ -37,7 +37,7 @@
|
||||
|
||||
/* Implemented in linker_md.c */
|
||||
|
||||
void dbgsysBuildLibName(char *, int, char *, char *);
|
||||
void dbgsysBuildLibName(char *, int, const char *, const char *);
|
||||
void * dbgsysLoadLibrary(const char *, char *err_buf, int err_buflen);
|
||||
void dbgsysUnloadLibrary(void *);
|
||||
void * dbgsysFindLibraryEntry(void *, const char *);
|
||||
|
@ -97,12 +97,12 @@ findTransportOnLoad(void *handle)
|
||||
|
||||
/* Load transport library (directory=="" means do system search) */
|
||||
static void *
|
||||
loadTransportLibrary(char *libdir, char *name)
|
||||
loadTransportLibrary(const char *libdir, const char *name)
|
||||
{
|
||||
void *handle;
|
||||
char libname[MAXPATHLEN+2];
|
||||
char buf[MAXPATHLEN*2+100];
|
||||
char *plibdir;
|
||||
const char *plibdir;
|
||||
|
||||
/* Convert libdir from UTF-8 to platform encoding */
|
||||
plibdir = NULL;
|
||||
@ -131,12 +131,12 @@ loadTransportLibrary(char *libdir, char *name)
|
||||
* JDK 1.2 javai.c v1.61
|
||||
*/
|
||||
static jdwpError
|
||||
loadTransport(char *name, jdwpTransportEnv **transportPtr)
|
||||
loadTransport(const char *name, jdwpTransportEnv **transportPtr)
|
||||
{
|
||||
JNIEnv *env;
|
||||
jdwpTransport_OnLoad_t onLoad;
|
||||
void *handle;
|
||||
char *libdir;
|
||||
const char *libdir;
|
||||
|
||||
/* Make sure library name is not empty */
|
||||
if (name == NULL) {
|
||||
|
@ -69,7 +69,7 @@ unsigned md_htonl(unsigned l);
|
||||
unsigned md_ntohs(unsigned short s);
|
||||
unsigned md_ntohl(unsigned l);
|
||||
|
||||
void md_build_library_name(char *holder, int holderlen, char *pname, char *fname);
|
||||
void md_build_library_name(char *holder, int holderlen, const char *pname, const char *fname);
|
||||
void * md_load_library(const char *name, char *err_buf, int err_buflen);
|
||||
void md_unload_library(void *handle);
|
||||
void * md_find_library_entry(void *handle, const char *name);
|
||||
|
@ -55,34 +55,27 @@
|
||||
#endif
|
||||
|
||||
static void dll_build_name(char* buffer, size_t buflen,
|
||||
const char* pname, const char* fname) {
|
||||
// Based on os_solaris.cpp
|
||||
const char* paths, const char* fname) {
|
||||
char *path, *paths_copy, *next_token;
|
||||
|
||||
char *path_sep = PATH_SEPARATOR;
|
||||
char *pathname = (char *)pname;
|
||||
*buffer = '\0';
|
||||
while (strlen(pathname) > 0) {
|
||||
char *p = strchr(pathname, *path_sep);
|
||||
if (p == NULL) {
|
||||
p = pathname + strlen(pathname);
|
||||
paths_copy = strdup(paths);
|
||||
if (paths_copy == NULL) {
|
||||
return;
|
||||
}
|
||||
/* check for NULL path */
|
||||
if (p == pathname) {
|
||||
continue;
|
||||
}
|
||||
(void)snprintf(buffer, buflen, "%.*s/lib%s." LIB_SUFFIX, (int)(p - pathname),
|
||||
pathname, fname);
|
||||
|
||||
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) {
|
||||
break;
|
||||
}
|
||||
if (*p == '\0') {
|
||||
pathname = p;
|
||||
} else {
|
||||
pathname = p + 1;
|
||||
}
|
||||
*buffer = '\0';
|
||||
path = strtok_r(NULL, PATH_SEPARATOR, &next_token);
|
||||
}
|
||||
|
||||
free(paths_copy);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -103,7 +96,7 @@ dbgsysBuildFunName(char *name, int nameLen, int args_size, int encodingIndex)
|
||||
* appropriate pre and extensions to a filename and the path
|
||||
*/
|
||||
void
|
||||
dbgsysBuildLibName(char *holder, int holderlen, char *pname, char *fname)
|
||||
dbgsysBuildLibName(char *holder, int holderlen, const char *pname, const char *fname)
|
||||
{
|
||||
const int pnamelen = pname ? strlen(pname) : 0;
|
||||
|
||||
|
@ -381,38 +381,32 @@ md_ntohl(unsigned l)
|
||||
}
|
||||
|
||||
static void dll_build_name(char* buffer, size_t buflen,
|
||||
const char* pname, const char* fname) {
|
||||
// Loosely based on os_solaris.cpp
|
||||
const char* paths, const char* fname) {
|
||||
char *path, *paths_copy, *next_token;
|
||||
|
||||
char *pathname = (char *)pname;
|
||||
*buffer = '\0';
|
||||
while (strlen(pathname) > 0) {
|
||||
char *p = strchr(pathname, ':');
|
||||
if (p == NULL) {
|
||||
p = pathname + strlen(pathname);
|
||||
paths_copy = strdup(paths);
|
||||
if (paths_copy == NULL) {
|
||||
return;
|
||||
}
|
||||
/* check for NULL path */
|
||||
if (p == pathname) {
|
||||
continue;
|
||||
}
|
||||
(void)snprintf(buffer, buflen, "%.*s/lib%s" JNI_LIB_SUFFIX,
|
||||
(int)(p - pathname), pathname, fname);
|
||||
|
||||
next_token = NULL;
|
||||
path = strtok_r(paths_copy, ":", &next_token);
|
||||
|
||||
while (path != NULL) {
|
||||
snprintf(buffer, buflen, "%s/lib%s" JNI_LIB_SUFFIX, path, fname);
|
||||
if (access(buffer, F_OK) == 0) {
|
||||
break;
|
||||
}
|
||||
if (*p == '\0') {
|
||||
pathname = p;
|
||||
} else {
|
||||
pathname = p + 1;
|
||||
}
|
||||
*buffer = '\0';
|
||||
path = strtok_r(NULL, ":", &next_token);
|
||||
}
|
||||
|
||||
free(paths_copy);
|
||||
}
|
||||
|
||||
/* Create the actual fill filename for a dynamic library. */
|
||||
void
|
||||
md_build_library_name(char *holder, int holderlen, char *pname, char *fname)
|
||||
md_build_library_name(char *holder, int holderlen, const char *pname, const char *fname)
|
||||
{
|
||||
int pnamelen;
|
||||
|
||||
|
@ -39,38 +39,27 @@
|
||||
#include "path_md.h"
|
||||
|
||||
static void dll_build_name(char* buffer, size_t buflen,
|
||||
const char* pname, const char* fname) {
|
||||
// Based on os_windows.cpp
|
||||
const char* paths, const char* fname) {
|
||||
char *path, *paths_copy, *next_token;
|
||||
|
||||
char *path_sep = PATH_SEPARATOR;
|
||||
char *pathname = (char *)pname;
|
||||
*buffer = '\0';
|
||||
while (strlen(pathname) > 0) {
|
||||
char *p = strchr(pathname, *path_sep);
|
||||
if (p == NULL) {
|
||||
p = pathname + strlen(pathname);
|
||||
}
|
||||
/* check for NULL path */
|
||||
if (p == pathname) {
|
||||
continue;
|
||||
}
|
||||
if (*(p-1) == ':' || *(p-1) == '\\') {
|
||||
(void)_snprintf(buffer, buflen, "%.*s%s.dll", (int)(p - pathname),
|
||||
pathname, fname);
|
||||
} else {
|
||||
(void)_snprintf(buffer, buflen, "%.*s\\%s.dll", (int)(p - pathname),
|
||||
pathname, fname);
|
||||
paths_copy = strdup(paths);
|
||||
if (paths_copy == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
next_token = NULL;
|
||||
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) {
|
||||
break;
|
||||
}
|
||||
if (*p == '\0') {
|
||||
pathname = p;
|
||||
} else {
|
||||
pathname = p + 1;
|
||||
}
|
||||
*buffer = '\0';
|
||||
path = strtok_s(NULL, PATH_SEPARATOR, &next_token);
|
||||
}
|
||||
|
||||
free(paths_copy);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -113,7 +102,7 @@ dbgsysGetLastErrorString(char *buf, int len)
|
||||
* Build a machine dependent library name out of a path and file name.
|
||||
*/
|
||||
void
|
||||
dbgsysBuildLibName(char *holder, int holderlen, char *pname, char *fname)
|
||||
dbgsysBuildLibName(char *holder, int holderlen, const char *pname, const char *fname)
|
||||
{
|
||||
const int pnamelen = pname ? (int)strlen(pname) : 0;
|
||||
|
||||
|
@ -368,42 +368,32 @@ get_last_error_string(char *buf, int len)
|
||||
}
|
||||
|
||||
static void dll_build_name(char* buffer, size_t buflen,
|
||||
const char* pname, const char* fname) {
|
||||
// Loosley based on os_windows.cpp
|
||||
const char* paths, const char* fname) {
|
||||
char *path, *paths_copy, *next_token;
|
||||
|
||||
char *pathname = (char *)pname;
|
||||
*buffer = '\0';
|
||||
while (strlen(pathname) > 0) {
|
||||
char *p = strchr(pathname, ';');
|
||||
if (p == NULL) {
|
||||
p = pathname + strlen(pathname);
|
||||
}
|
||||
/* check for NULL path */
|
||||
if (p == pathname) {
|
||||
continue;
|
||||
}
|
||||
if (*(p-1) == ':' || *(p-1) == '\\') {
|
||||
(void)_snprintf(buffer, buflen, "%.*s%s.dll", (int)(p - pathname),
|
||||
pathname, fname);
|
||||
} else {
|
||||
(void)_snprintf(buffer, buflen, "%.*s\\%s.dll", (int)(p - pathname),
|
||||
pathname, fname);
|
||||
paths_copy = strdup(paths);
|
||||
if (paths_copy == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
next_token = NULL;
|
||||
path = strtok_s(paths_copy, ";", &next_token);
|
||||
|
||||
while (path != NULL) {
|
||||
_snprintf(buffer, buflen, "%s\\%s.dll", path, fname);
|
||||
if (_access(buffer, 0) == 0) {
|
||||
break;
|
||||
}
|
||||
if (*p == '\0') {
|
||||
pathname = p;
|
||||
} else {
|
||||
pathname = p + 1;
|
||||
}
|
||||
*buffer = '\0';
|
||||
path = strtok_s(NULL, ";", &next_token);
|
||||
}
|
||||
|
||||
free(paths_copy);
|
||||
}
|
||||
|
||||
/* Build a machine dependent library name out of a path and file name. */
|
||||
void
|
||||
md_build_library_name(char *holder, int holderlen, char *pname, char *fname)
|
||||
md_build_library_name(char *holder, int holderlen, const char *pname, const char *fname)
|
||||
{
|
||||
int pnamelen;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user