I tried to attach to a core file that was generated while running the jhsdb command (yes, using SA to debug SA). SA crashed when I did this, and after fixing the crash, it was still unable to attach.
The issue is with ps_core.c::get_real_path(), which tries to find the path to the java libs. It starts by searching for bin/java in the path to the executable (execpath), and uses that to find the path to the java libraries. However, that doesn't work if the execpath ends in bin/jhsdb, or any other java launcher in the bin directory. It then checks JAVA_HOME. If that is null, it then falls into the following code:
char* dyldpath = getenv("DYLD_LIBRARY_PATH");
char* save_ptr;
char* dypath = strtok_r(dyldpath, ":", &save_ptr);
This gets a SEGV if DYLD_LIBRARY_PATH is null (the crash I mentioned above), so one fix needed is to add the null check. If the DYLD_LIBRARY_PATH check fails, then it gives up, so another change I made that helped with the jhsdb case was as a last resort to have it just search for bin/ instead of bin/java.
The issue is with ps_core.c::get_real_path(), which tries to find the path to the java libs. It starts by searching for bin/java in the path to the executable (execpath), and uses that to find the path to the java libraries. However, that doesn't work if the execpath ends in bin/jhsdb, or any other java launcher in the bin directory. It then checks JAVA_HOME. If that is null, it then falls into the following code:
char* dyldpath = getenv("DYLD_LIBRARY_PATH");
char* save_ptr;
char* dypath = strtok_r(dyldpath, ":", &save_ptr);
This gets a SEGV if DYLD_LIBRARY_PATH is null (the crash I mentioned above), so one fix needed is to add the null check. If the DYLD_LIBRARY_PATH check fails, then it gives up, so another change I made that helped with the jhsdb case was as a last resort to have it just search for bin/ instead of bin/java.
- relates to
-
JDK-8232973 Potential infinite loop in macOS hotspot agent
- Resolved