Information Security Stack Exchange is a question and answer site for information security professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Jumping from

What are the security implications of both approach ?

  • System.loadLibrary("_name_");
    • Automatically searches for a library named "" in $LD_LIBRARY_PATH
  • System.load("/PATH/TO/");
    • do load "/PATH/TO/"
share|improve this question
You've mentioned loadLibrary two times. Shouldn't the second one be System.load? – Rob W May 10 '13 at 20:07
Correct ! I'm editing right now – Cerber May 11 '13 at 14:30
up vote 4 down vote accepted

System.loadLibrary() refuses to load "libraries" with the path separator appearing in the name; see this excerpt from Java's source code (in

synchronized void loadLibrary0(Class fromClass, String libname) {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
    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.

share|improve this answer

Relying on the calling system to help locate things can certainly lead down odd paths. The biggest problem is that the system may provide a file that wasn't intended to be loaded by the application. If an attacker can place a file in a location that falls under the search, then the attacker can inject arbitrary code into the application and execute it. E.g. an arbitrary code execution vulnerability (

If you specify the exact path, you have the ability to protect the loaded file through things like file permissions, etc.

share|improve this answer
extra question : what if the library path has to be passed by command line ? I have to replace a failing autodiscovery mecanism and, following the KISS principle, would tend to use System.load(..) with the full path provided by the command line at runtime – Cerber May 10 '13 at 18:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.