aboutsummaryrefslogtreecommitdiff
path: root/java/android/OlmLibSdk
diff options
context:
space:
mode:
authorylecollen <ylecollen@amdocs.com>2017-01-05 10:16:14 +0100
committerylecollen <ylecollen@amdocs.com>2017-01-05 10:16:14 +0100
commiteec8a50cafc75c025a98133520e8d8e9cf97e115 (patch)
treef98a23c6ab011b374872b53b4d31058615078082 /java/android/OlmLibSdk
parent90c55806c081b2610a08a48a6cc897e0121ab3b7 (diff)
Move the exception test
Diffstat (limited to 'java/android/OlmLibSdk')
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp24
1 files changed, 14 insertions, 10 deletions
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);
+ }
}
}