Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing NULL checks #871

Merged
merged 1 commit into from
Jun 12, 2024
Merged
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
6 changes: 6 additions & 0 deletions openssl-dynamic/src/main/c/cert_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ static int compress(jobject compression_algorithm, jmethodID compress_method, SS
return 0; // Unable to reserve space for compressed data
}
jbyte* resultData = (*e)->GetByteArrayElements(e, resultArray, NULL);
if (resultData == NULL) {
return 0;
}
memcpy(outData, resultData, resultLen);
(*e)->ReleaseByteArrayElements(e, resultArray, resultData, JNI_ABORT);
if (!CBB_did_write(out, resultLen)) {
Expand Down Expand Up @@ -102,6 +105,9 @@ static int decompress(jobject compression_algorithm, jmethodID decompress_method
return 0; // Unable to allocate certificate decompression buffer
}
jbyte* resultData = (*e)->GetByteArrayElements(e, resultArray, NULL);
if (resultData == NULL) {
return 0;
}
memcpy(outData, resultData, uncompressed_len);
(*e)->ReleaseByteArrayElements(e, resultArray, resultData, JNI_ABORT);
return 1; // Success
Expand Down
1 change: 0 additions & 1 deletion openssl-dynamic/src/main/c/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,6 @@ TCN_IMPLEMENT_CALL(jbyteArray, SSL, getSessionId)(TCN_STDARGS, jlong ssl)
return NULL;
}


if ((bArray = (*e)->NewByteArray(e, len)) == NULL) {
return NULL;
}
Expand Down
24 changes: 19 additions & 5 deletions openssl-dynamic/src/main/c/sslcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,11 @@ TCN_IMPLEMENT_CALL(void, SSLContext, setSessionTicketKeys0)(TCN_STDARGS, jlong c
return;
}

b = (*e)->GetByteArrayElements(e, keys, NULL);
if ((b = (*e)->GetByteArrayElements(e, keys, NULL)) == NULL) {
tcn_ThrowException(e, "GetByteArrayElements() returned null");
return;
}

for (i = 0; i < cnt; ++i) {
key = b + (SSL_SESSION_TICKET_KEY_SIZE * i);
memcpy(ticket_keys[i].key_name, key, 16);
Expand Down Expand Up @@ -1495,7 +1499,7 @@ static jbyteArray get_certs(JNIEnv *e, SSL* ssl, STACK_OF(X509)* chain) {
length = i2d_X509(cert, &buf);
#endif // OPENSSL_IS_BORINGSSL

if (length <= 0 || (bArray = (*e)->NewByteArray(e, length)) == NULL ) {
if (length <= 0 || (bArray = (*e)->NewByteArray(e, length)) == NULL) {
NETTY_JNI_UTIL_DELETE_LOCAL(e, array);
array = NULL;
goto complete;
Expand Down Expand Up @@ -2173,7 +2177,11 @@ static enum ssl_private_key_result_t tcn_private_key_sign_java(SSL *ssl, uint8_t
} else {
arrayLen = (*e)->GetArrayLength(e, resultBytes);
if (max_out >= arrayLen) {
b = (*e)->GetByteArrayElements(e, resultBytes, NULL);
if ((b = (*e)->GetByteArrayElements(e, resultBytes, NULL)) == NULL) {
ret = ssl_private_key_failure;
goto complete;
}

memcpy(out, b, arrayLen);
(*e)->ReleaseByteArrayElements(e, resultBytes, b, JNI_ABORT);
*out_len = arrayLen;
Expand Down Expand Up @@ -2238,7 +2246,11 @@ static enum ssl_private_key_result_t tcn_private_key_decrypt_java(SSL *ssl, uint
} else {
arrayLen = (*e)->GetArrayLength(e, resultBytes);
if (max_out >= arrayLen) {
b = (*e)->GetByteArrayElements(e, resultBytes, NULL);
if ((b = (*e)->GetByteArrayElements(e, resultBytes, NULL)) == NULL) {
ret = ssl_private_key_failure;
goto complete;
}

memcpy(out, b, arrayLen);
(*e)->ReleaseByteArrayElements(e, resultBytes, b, JNI_ABORT);
*out_len = arrayLen;
Expand Down Expand Up @@ -2300,7 +2312,9 @@ static enum ssl_private_key_result_t tcn_private_key_complete_java(SSL *ssl, uin
// belong to us.
return ssl_private_key_failure;
}
b = (*e)->GetByteArrayElements(e, resultBytes, NULL);
if ((b = (*e)->GetByteArrayElements(e, resultBytes, NULL)) == NULL) {
return ssl_private_key_failure;
}
memcpy(out, b, arrayLen);
(*e)->ReleaseByteArrayElements(e, resultBytes, b, JNI_ABORT);
*out_len = arrayLen;
Expand Down
Loading