F-10746: return an error when the ECC shared-secret callback throws, instead of using an undefined result

pull/402/head
Chris Conlon 2026-08-17 15:49:34 -06:00
parent b769f278f7
commit b464d479b4
1 changed files with 13 additions and 2 deletions

View File

@ -3903,12 +3903,13 @@ int NativeEccSharedSecretCb(WOLFSSL* ssl, ecc_key* otherKey,
unsigned char* out, unsigned int* outlen, int side, void* ctx)
{
int ret;
int cbException = 0; /* Java callback threw an exception */
jint retval = 0;
JNIEnv* jenv = NULL; /* JNI Environment */
int needsDetach = 0; /* Should we explicitly detach? */
jobject* g_cachedSSLObj; /* WolfSSLSession cached object */
jobject* g_cachedSSLObj; /* WolfSSLSession cached object */
jobject ctxRef; /* WolfSSLContext object */
jmethodID eccSharedSecretMethodId;
@ -4138,7 +4139,7 @@ int NativeEccSharedSecretCb(WOLFSSL* ssl, ecc_key* otherKey,
(jobject)(*g_cachedSSLObj), eccKeyObject, pubKeyDerBB,
j_pubKeyDerSz, outBB, j_outSz, (jint)side);
CheckException(jenv);
cbException = CheckException(jenv);
(*jenv)->DeleteLocalRef(jenv, ctxRef);
(*jenv)->DeleteLocalRef(jenv, eccKeyObject);
(*jenv)->DeleteLocalRef(jenv, pubKeyDerBB);
@ -4146,6 +4147,16 @@ int NativeEccSharedSecretCb(WOLFSSL* ssl, ecc_key* otherKey,
XFREE(tmpKeyDer, otherKey->heap, DYNAMIC_TYPE_TMP_BUFFER);
}
if (cbException) {
/* Java callback threw, do not use the undefined result */
(*jenv)->DeleteLocalRef(jenv, j_pubKeyDerSz);
(*jenv)->DeleteLocalRef(jenv, j_outSz);
(*jenv)->DeleteLocalRef(jenv, outBB);
if (needsDetach)
(*g_vm)->DetachCurrentThread(g_vm);
return -1;
}
if (retval == 0) {
/* copy j_outSz into outlen, j_pubKeyDerSz into pubKeySz */
(*jenv)->GetLongArrayRegion(jenv, j_outSz, 0, 1, &tmpVal);