src/windows/demo/jvmti/hprof/hprof_md.c
Print this page
rev 6659 : 8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
Reviewed-by:
@@ -366,46 +366,36 @@
return 0;
}
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;
pnamelen = pname ? (int)strlen(pname) : 0;