fix: JNI_OnLoad case25 Jul 2020 | fix jni
Subsurfer reported several issues related to JNI. Quick test exposed two issues:
JNI FindClass was not successful when was called from JNI_OnLoad (as result of System.loadLibrary for example)
root case: top java class on the stack was
java.lang.Runtime and its classLoader was NULL (corresponds to
BootClassLoader). As result user class was looked in BC list and failed.
fix: use systemClassLoader in case as top java class is BC class.
issue is similar to robovm/robovm#352
If application uses a dynamic framework or library that exposes JNI_OnLoad it being called in context of application image. This happens as dyld loads all symbols from libraries referenced by LC_LOAD_DYLIB command. as result library JNI_OnLoad got called on early state while JNI is not initialized yet. This caused GPF due null pointer de-reference. fix: ignore JNI_OnLoad for application image
Fix was delivered as PR507.