aboutsummaryrefslogtreecommitdiff
path: root/java/android/OlmLibSdk/olm-sdk
diff options
context:
space:
mode:
Diffstat (limited to 'java/android/OlmLibSdk/olm-sdk')
-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);
+ }
}
}