summaryrefslogtreecommitdiffstats
path: root/vm/Jni.c
diff options
context:
space:
mode:
authorAndy McFadden <fadden@android.com>2009-06-24 16:56:06 -0700
committerAndy McFadden <fadden@android.com>2009-06-24 16:56:06 -0700
commit72d61fba8ad3d3c720e6df61c7ae07baa4fd7838 (patch)
treea3aac49a8569433d87dc66bfd6227f61ccc2c53c /vm/Jni.c
parentcda8f8abd1d02f5ab58add1ebb23f20fdab6341c (diff)
downloadandroid_dalvik-72d61fba8ad3d3c720e6df61c7ae07baa4fd7838.tar.gz
android_dalvik-72d61fba8ad3d3c720e6df61c7ae07baa4fd7838.tar.bz2
android_dalvik-72d61fba8ad3d3c720e6df61c7ae07baa4fd7838.zip
Check for failure in GetDirectBufferAddress.
We now check for a null result or a pending exception in the JNI GetDirectBufferAddress function. This prevents a VM crash when somebody tries to get the address of a non-direct buffer. For internal bug 1926596.
Diffstat (limited to 'vm/Jni.c')
-rw-r--r--vm/Jni.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/vm/Jni.c b/vm/Jni.c
index 4bca8d48e..e56e68d7e 100644
--- a/vm/Jni.c
+++ b/vm/Jni.c
@@ -2746,6 +2746,10 @@ static void* GetDirectBufferAddress(JNIEnv * env, jobject buf)
jmethodID toLongMethod;
void* result = NULL;
+ /*
+ * Start by determining if the object supports the DirectBuffer
+ * interfaces. Note this does not guarantee that it's a direct buffer.
+ */
tempClass = (*env)->FindClass(env,
"org/apache/harmony/nio/internal/DirectBuffer");
if(!tempClass)
@@ -2764,6 +2768,20 @@ static void* GetDirectBufferAddress(JNIEnv * env, jobject buf)
goto bail;
}
platformAddr = (*env)->CallObjectMethod(env, buf, tempMethod);
+
+ /*
+ * If this isn't a direct buffer, platformAddr will be NULL and/or an
+ * exception will have been thrown.
+ */
+ if ((*env)->ExceptionCheck(env)) {
+ (*env)->ExceptionClear(env);
+ platformAddr = NULL;
+ }
+ if (platformAddr == NULL) {
+ LOGV("Got request for address of non-direct buffer\n");
+ goto bail;
+ }
+
platformAddrClass = (*env)->FindClass (env,
"org/apache/harmony/luni/platform/PlatformAddress");
if(!platformAddrClass)