Move the exception test
This commit is contained in:
parent
90c55806c0
commit
eec8a50caf
1 changed files with 14 additions and 10 deletions
|
@ -62,22 +62,26 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize)
|
||||||
newObj = env->NewObject(cls, constructor);
|
newObj = env->NewObject(cls, constructor);
|
||||||
jbyteArray tempByteArray = env->NewByteArray(bufferLen);
|
jbyteArray tempByteArray = env->NewByteArray(bufferLen);
|
||||||
|
|
||||||
if (newObj && tempByteArray && !env->ExceptionOccurred())
|
if (newObj && tempByteArray)
|
||||||
{
|
{
|
||||||
env->CallVoidMethod(newObj, nextByteMethod, tempByteArray);
|
env->CallVoidMethod(newObj, nextByteMethod, tempByteArray);
|
||||||
jbyte* buffer = env->GetByteArrayElements(tempByteArray, NULL);
|
|
||||||
|
|
||||||
if (buffer)
|
if (!env->ExceptionOccurred())
|
||||||
{
|
{
|
||||||
memcpy(*aBuffer2Ptr, buffer, bufferLen);
|
jbyte* buffer = env->GetByteArrayElements(tempByteArray, NULL);
|
||||||
retCode = true;
|
|
||||||
|
|
||||||
// clear tempByteArray to hide sensitive data.
|
if (buffer)
|
||||||
memset(buffer, 0, bufferLen);
|
{
|
||||||
env->SetByteArrayRegion(tempByteArray, 0, bufferLen, buffer);
|
memcpy(*aBuffer2Ptr, buffer, bufferLen);
|
||||||
|
retCode = true;
|
||||||
|
|
||||||
// ensure that the buffer is released
|
// clear tempByteArray to hide sensitive data.
|
||||||
env->ReleaseByteArrayElements(tempByteArray, buffer, JNI_ABORT);
|
memset(buffer, 0, bufferLen);
|
||||||
|
env->SetByteArrayRegion(tempByteArray, 0, bufferLen, buffer);
|
||||||
|
|
||||||
|
// ensure that the buffer is released
|
||||||
|
env->ReleaseByteArrayElements(tempByteArray, buffer, JNI_ABORT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue