System.loadLibrary()
refuses to load "libraries" with the path separator appearing in the name; see this excerpt from Java's source code (in java.lang.Runtime.java
):
synchronized void loadLibrary0(Class fromClass, String libname) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkLink(libname);
}
if (libname.indexOf((int)File.separatorChar) != -1) {
throw new UnsatisfiedLinkError(
"Directory separator should not appear in library name: " + libname);
}
ClassLoader.loadLibrary(fromClass, libname, false);
}
As such, you could imagine allowing System.loadLibrary()
but rejecting System.load()
, giving access to only a specific set of loadable "safe" libraries... however, this seems indirect and fragile. The "normal" way of restricting native code loading is through SystemManager.checkLink(), which is called from both System.load()
and System.loadLibrary()
. In that case, there is no real difference in security between the two methods.