From eec8a50cafc75c025a98133520e8d8e9cf97e115 Mon Sep 17 00:00:00 2001 From: ylecollen Date: Thu, 5 Jan 2017 10:16:14 +0100 Subject: Move the exception test --- .../olm-sdk/src/main/jni/olm_jni_helper.cpp | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'java/android') diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp index e8661c7..7146f4e 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp +++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp @@ -62,22 +62,26 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize) newObj = env->NewObject(cls, constructor); jbyteArray tempByteArray = env->NewByteArray(bufferLen); - if (newObj && tempByteArray && !env->ExceptionOccurred()) + if (newObj && tempByteArray) { env->CallVoidMethod(newObj, nextByteMethod, tempByteArray); - jbyte* buffer = env->GetByteArrayElements(tempByteArray, NULL); - if (buffer) + if (!env->ExceptionOccurred()) { - memcpy(*aBuffer2Ptr, buffer, bufferLen); - retCode = true; + jbyte* buffer = env->GetByteArrayElements(tempByteArray, NULL); - // clear tempByteArray to hide sensitive data. - memset(buffer, 0, bufferLen); - env->SetByteArrayRegion(tempByteArray, 0, bufferLen, buffer); + if (buffer) + { + memcpy(*aBuffer2Ptr, buffer, bufferLen); + retCode = true; - // ensure that the buffer is released - env->ReleaseByteArrayElements(tempByteArray, buffer, JNI_ABORT); + // clear tempByteArray to hide sensitive data. + memset(buffer, 0, bufferLen); + env->SetByteArrayRegion(tempByteArray, 0, bufferLen, buffer); + + // ensure that the buffer is released + env->ReleaseByteArrayElements(tempByteArray, buffer, JNI_ABORT); + } } } -- cgit v1.2.3