Skip to content

Commit 416c74b

Browse files
committed
Harden JNI null checks and ref cleanup
1 parent 2baee55 commit 416c74b

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

native/com_wolfssl_WolfSSLContext.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,9 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLContext_setCipherList
859859
}
860860

861861
cipherList = (*jenv)->GetStringUTFChars(jenv, list, 0);
862+
if (cipherList == NULL) {
863+
return (jint)MEMORY_E;
864+
}
862865

863866
ret = (jint) wolfSSL_CTX_set_cipher_list(ctx, cipherList);
864867

@@ -1179,6 +1182,7 @@ int NativeIORecvCb(WOLFSSL *ssl, char *buf, int sz, void *ctx)
11791182
if (!g_sslIORecvMethodId) {
11801183
(*jenv)->ThrowNew(jenv, excClass,
11811184
"Cached recv callback method ID is null in NativeIORecvCb");
1185+
(*jenv)->DeleteLocalRef(jenv, ctxRef);
11821186
if (needsDetach)
11831187
(*g_vm)->DetachCurrentThread(g_vm);
11841188
return WOLFSSL_CBIO_ERR_GENERAL;
@@ -1782,10 +1786,15 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLContext_setCRLCb
17821786
}
17831787
(*jenv)->ThrowNew(jenv, excClass,
17841788
"error storing global missing CTX CRL callback interface");
1789+
return (jint)SSL_FAILURE;
17851790
}
17861791

17871792
ret = wolfSSL_CTX_SetCRL_Cb(ctx, NativeCtxMissingCRLCallback);
17881793
}
1794+
else {
1795+
/* clear native callback when Java side is disabling */
1796+
ret = wolfSSL_CTX_SetCRL_Cb(ctx, NULL);
1797+
}
17891798

17901799
return (jint)ret;
17911800
#else
@@ -1952,6 +1961,9 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLContext_setOCSPOverrideUrl
19521961
}
19531962

19541963
url = (*jenv)->GetStringUTFChars(jenv, urlString, 0);
1964+
if (url == NULL) {
1965+
return (jint)MEMORY_E;
1966+
}
19551967

19561968
ret = (jint) wolfSSL_CTX_SetOCSP_OverrideURL(ctx, url);
19571969

@@ -6766,6 +6778,9 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLContext_set1SigAlgsList
67666778
}
67676779

67686780
sigAlgList = (*jenv)->GetStringUTFChars(jenv, list, 0);
6781+
if (sigAlgList == NULL) {
6782+
return (jint)MEMORY_E;
6783+
}
67696784

67706785
ret = wolfSSL_CTX_set1_sigalgs_list(ctx, sigAlgList);
67716786

native/com_wolfssl_WolfSSLSession.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,9 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_setCipherList
24702470
}
24712471

24722472
cipherList= (*jenv)->GetStringUTFChars(jenv, list, 0);
2473+
if (cipherList == NULL) {
2474+
return (jint)MEMORY_E;
2475+
}
24732476

24742477
ret = (jint) wolfSSL_set_cipher_list(ssl, cipherList);
24752478

@@ -6380,6 +6383,9 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_set1SigAlgsList
63806383
}
63816384

63826385
sigAlgList = (*jenv)->GetStringUTFChars(jenv, list, 0);
6386+
if (sigAlgList == NULL) {
6387+
return (jint)MEMORY_E;
6388+
}
63836389

63846390
ret = wolfSSL_set1_sigalgs_list(ssl, sigAlgList);
63856391

0 commit comments

Comments
 (0)