Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions native/src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,7 @@ TCN_IMPLEMENT_CALL(jobjectArray, SSL, getPeerCertChain)(TCN_STDARGS,

buf = NULL;
length = i2d_X509(cert, &buf);
if (length < 0) {
OPENSSL_free(buf);
if (length <= 0) {
/* In case of error just return an empty byte[][] */
return (*e)->NewObjectArray(e, 0, byteArrayClass, NULL);
}
Expand Down Expand Up @@ -953,6 +952,11 @@ TCN_IMPLEMENT_CALL(jbyteArray, SSL, getPeerCertificate)(TCN_STDARGS,

length = i2d_X509(cert, &buf);

if (length <= 0) {
X509_free(cert);
return NULL;
}

bArray = (*e)->NewByteArray(e, length);
(*e)->SetByteArrayRegion(e, bArray, 0, length, (jbyte*) buf);

Expand Down
4 changes: 1 addition & 3 deletions native/src/sslcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1754,11 +1754,9 @@ static int SSL_cert_verify(X509_STORE_CTX *ctx, void *arg) {

buf = NULL;
length = i2d_X509(cert, &buf);
if (length < 0) {
if (length <= 0) {
// In case of error just return an empty byte[][]
array = (*e)->NewObjectArray(e, 0, byteArrayClass, NULL);
// We need to delete the local references so we not leak memory as this method is called via callback.
OPENSSL_free(buf);
break;
}
bArray = (*e)->NewByteArray(e, length);
Expand Down