This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit

Difference between revisions of "Unsafe JNI"

Jump to: navigation, search
(Reverting to last version not containing links to
Line 1: Line 1:
[ subaru auto dealer
] [ asian womens center
] [ game auto
] [ african british defended queen that
] [ asian cups
] [ maxson automatic machinery
] [ star news paper in south africa
] [ hot asian schoolgirl
] [ australian population growth rate
] [ antivirus for w32.spybot.worm
] [ australian artists female
] [ asian girl model thumbnail young
] [ map of melbourne suburbs australia
] [ i run my antivirus and the computer shuts down
] [ australian book club
] [ bmw australia finance ltd] [ lazy boy recliners australia
] [ automotive classified domain public script
] [ african flag picture
] [ asian gallery man
] [ teamasians
] [ african american line literature time
] [ buff asians
] [ serial for avg antivirus 7.1
] [ bill gates africa donation] [ top] [ africa forced removal south
] [ james mangan automation
] [ job agencies sydney australia] [ australian education union tasmania
] [ asian gift store
] [ congentital adrenal hyperplasia
] [ top] [ auto upholstery in az
] [ car seat baby capsule australia
] [ auto service company toyota
] [ links] [ automotive suspension part
] [ eztrust antivirus download
] [ top] [ south african language dictionary
] [ australian humour
] [ ontegra automotive] [ budget car rental in australia
] [ asian chiks
] [ asian 4 u natalia
] [ inoculateit antivirus avboot
] [ auto restore windows xp
] [ etrust antivirus 7.1 retail
] [ pretty asia women]  
Line 126: Line 84:
* [1] B. Stearns. The Java™ Tutorial: The Java Native Interface. Sun Microsystems, 2005.
* [1] B. Stearns. The Java™ Tutorial: The Java Native Interface. Sun Microsystems, 2005.
* [2] Fortify Descriptions.
* [2] Fortify Descriptions.

Revision as of 15:59, 27 May 2009 This is a Vulnerability. To view all vulnerabilities, please see the Vulnerability Category page.

This article includes content generously donated to OWASP by MicroFocus Logo.png

Last revision (mm/dd/yy): 05/27/2009

Vulnerabilities Table of Contents


Improper use of the Java Native Interface (JNI) can render Java applications vulnerable to security flaws in other languages.

Unsafe JNI errors occur when a Java application uses JNI to call code written in another programming language.

Risk Factors



The following Java code defines a class named Echo. The class declares one native method (defined below), which uses C to echo commands entered on the console back to the user.

	class Echo {
		public native void runEcho();
		static {
		public static void main(String[] args) {
			new Echo().runEcho();

The following C code defines the native method implemented in the Echo class:

	#include <jni.h>
	#include "Echo.h"//the java class above compiled with javah
	#include <stdio.h>
	Java_Echo_runEcho(JNIEnv *env, jobject obj) 
		char buf[64]; 

Because the example is implemented in Java, it may appear that it is immune to memory issues like buffer overflow vulnerabilities. Although Java does do a good job of making memory operations safe, this protection does not extend to vulnerabilities occurring in source code written in other languages that are accessed using the Java Native Interface. Despite the memory protections offered in Java, the C code in this example is vulnerable to a buffer overflow because it makes use of gets(), which does not perform any bounds checking on its input.

The Sun Java(TM) Tutorial provides the following description of JNI [2]:

The JNI framework lets your native method utilize Java objects in the same way that Java code uses these objects. A native method can create Java objects, including arrays and strings, and then inspect and use these objects to perform its tasks. A native method can also inspect and use objects created by Java application code. A native method can even update Java objects that it created or that were passed to it, and these updated objects are available to the Java application. Thus, both the native language side and the Java side of an application can create, update, and access Java objects and then share these objects between them.

The vulnerability in the example above could easily be detected through a source code audit of the native method implementation. This may not be practical or possible depending on the availability of the C source code and the way the project is built, but in many cases it may suffice. However, the ability to share objects between Java and native methods expands the potential risk to much more insidious cases where improper data handling in Java may lead to unexpected vulnerabilities in native code or unsafe operations in native code corrupt data structures in Java.

Vulnerabilities in native code accessed through a Java application are typically exploited in the same manner as they are in applications written in the native language. The only challenge to such an attack is for the attacker to identify that the Java application uses native code to perform certain operations. This can be accomplished in a variety of ways, including identifying specific behaviors that are often implemented with native code or by exploiting a system information leak in the Java application that exposes its use of JNI [2].

Related Attacks

Related Vulnerabilities

Related Controls

Related Technical Impacts