8232973: Potential infinite loop in macOS hotspot agent
Reviewed-by: stuefe, cjplummer, sspitsyn
--- a/src/jdk.hotspot.agent/macosx/native/libsaproc/ps_core.c Mon Nov 04 11:33:15 2019 +0100
+++ b/src/jdk.hotspot.agent/macosx/native/libsaproc/ps_core.c Mon Nov 04 13:58:33 2019 +0100
@@ -364,7 +364,8 @@
strcpy(filepath, java_home);
} else {
char* dyldpath = getenv("DYLD_LIBRARY_PATH");
- char* dypath = strtok(dyldpath, ":");
+ char* save_ptr;
+ char* dypath = strtok_r(dyldpath, ":", &save_ptr);
while (dypath != NULL) {
strcpy(filepath, dypath);
strcat(filepath, filename);
@@ -372,7 +373,7 @@
strcpy(rpath, filepath);
return true;
}
- dypath = strtok(dyldpath, ":");
+ dypath = strtok_r(NULL, ":", &save_ptr);
}
// not found
return false;