diff options
author | Sebastien Hertz <shertz@google.com> | 2014-07-03 09:39:53 +0200 |
---|---|---|
committer | Sebastien Hertz <shertz@google.com> | 2014-07-03 11:18:06 +0200 |
commit | fa65e846362829d6e444bd88b12fe2496b3d5647 (patch) | |
tree | d17bdf533529d158278e2fbe64214ea71aa7e228 /runtime/jni_internal.cc | |
parent | 555377d55c37db860583e0655f63a1dacb589921 (diff) | |
download | art-fa65e846362829d6e444bd88b12fe2496b3d5647.tar.gz art-fa65e846362829d6e444bd88b12fe2496b3d5647.tar.bz2 art-fa65e846362829d6e444bd88b12fe2496b3d5647.zip |
More checks in JNI RegisterNatives
Throws NoSuchMethodError (and returns JNI_ERR) when given method name, method
signature or native function is null.
Bug: https://code.google.com/p/android/issues/detail?id=72293
Bug: 15886341
Change-Id: I1c0582d54031eaa58a6025a2417d65090a2a622a
Diffstat (limited to 'runtime/jni_internal.cc')
-rw-r--r-- | runtime/jni_internal.cc | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc index 0624281c20..845691d182 100644 --- a/runtime/jni_internal.cc +++ b/runtime/jni_internal.cc @@ -112,6 +112,17 @@ static void ThrowNoSuchMethodError(ScopedObjectAccess& soa, mirror::Class* c, kind, c->GetDescriptor().c_str(), name, sig); } +static void ReportInvalidJNINativeMethod(const ScopedObjectAccess& soa, mirror::Class* c, + const char* kind, jint idx, bool return_errors) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { + LOG(return_errors ? ERROR : FATAL) << "Failed to register native method in " + << PrettyDescriptor(c) << " in " << c->GetDexCache()->GetLocation()->ToModifiedUtf8() + << ": " << kind << " is null at index " << idx; + ThrowLocation throw_location = soa.Self()->GetCurrentLocationForThrow(); + soa.Self()->ThrowNewExceptionF(throw_location, "Ljava/lang/NoSuchMethodError;", + "%s is null at index %d", kind, idx); +} + static mirror::Class* EnsureInitialized(Thread* self, mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { if (LIKELY(klass->IsInitialized())) { @@ -2357,6 +2368,17 @@ class JNI { for (jint i = 0; i < method_count; ++i) { const char* name = methods[i].name; const char* sig = methods[i].signature; + const void* fnPtr = methods[i].fnPtr; + if (UNLIKELY(name == nullptr)) { + ReportInvalidJNINativeMethod(soa, c, "method name", i, return_errors); + return JNI_ERR; + } else if (UNLIKELY(sig == nullptr)) { + ReportInvalidJNINativeMethod(soa, c, "method signature", i, return_errors); + return JNI_ERR; + } else if (UNLIKELY(fnPtr == nullptr)) { + ReportInvalidJNINativeMethod(soa, c, "native function", i, return_errors); + return JNI_ERR; + } bool is_fast = false; if (*sig == '!') { is_fast = true; @@ -2384,7 +2406,7 @@ class JNI { VLOG(jni) << "[Registering JNI native method " << PrettyMethod(m) << "]"; - m->RegisterNative(soa.Self(), methods[i].fnPtr, is_fast); + m->RegisterNative(soa.Self(), fnPtr, is_fast); } return JNI_OK; } |