GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — QUIC: Correctly handle malloc errors during ssl context creation (#16… · netty/netty@dde3dd0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-native-quic/src/main/c
    • netty_quic_boringssl.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-native-quic/src/main/c/netty_quic_boringssl.c‎

Copy file name to clipboardExpand all lines: codec-native-quic/src/main/c/netty_quic_boringssl.c
+17-2Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,8 @@ static jlong netty_boringssl_SSLContext_new0(JNIEnv* env, jclass clazz, jboolean
10151015
jobject sessionCallbackRef = NULL;
10161016
jobject privateKeyMethodRef = NULL;
10171017
jobject sessionTicketCallbackRef = NULL;
1018-
1018+
SSL_CTX *ctx = NULL;
1019+
alpn_data* alpn = NULL;
10191020
if ((handshakeCompleteCallbackRef = (*env)->NewGlobalRef(env, handshakeCompleteCallback)) == NULL) {
10201021
goto error;
10211022
}
@@ -1055,7 +1056,7 @@ static jlong netty_boringssl_SSLContext_new0(JNIEnv* env, jclass clazz, jboolean
10551056
goto error;
10561057
}
10571058

1058-
SSL_CTX *ctx = SSL_CTX_new(TLS_with_buffers_method());
1059+
ctx = SSL_CTX_new(TLS_with_buffers_method());
10591060
// When using BoringSSL we want to use CRYPTO_BUFFER to reduce memory usage and minimize overhead as we do not need
10601061
// X509* at all and just need the raw bytes of the certificates to construct our Java X509Certificate.
10611062
//
@@ -1114,6 +1115,10 @@ static jlong netty_boringssl_SSLContext_new0(JNIEnv* env, jclass clazz, jboolean
11141115
if (alpn != NULL) {
11151116
// Fill the alpn_data struct
11161117
alpn->proto_data = OPENSSL_malloc(alpn_length);
1118+
if (alpn->proto_data == NULL) {
1119+
// malloc failed, most likely OOM.
1120+
goto error;
1121+
}
11171122
alpn->proto_len = alpn_length;
11181123
(*env)->GetByteArrayRegion(env, alpn_protos, 0, alpn_length, (jbyte*) alpn->proto_data);
11191124

@@ -1123,10 +1128,20 @@ static jlong netty_boringssl_SSLContext_new0(JNIEnv* env, jclass clazz, jboolean
11231128
} else {
11241129
SSL_CTX_set_alpn_protos(ctx, alpn->proto_data, alpn->proto_len);
11251130
}
1131+
} else {
1132+
// malloc failed, most likely OOM.
1133+
goto error;
11261134
}
11271135
}
11281136
return (jlong) ctx;
11291137
error:
1138+
if (ctx != NULL) {
1139+
SSL_CTX_free(ctx);
1140+
}
1141+
if (alpn != NULL) {
1142+
OPENSSL_free(alpn->proto_data);
1143+
OPENSSL_free(alpn);
1144+
}
11301145
if (handshakeCompleteCallbackRef != NULL) {
11311146
(*env)->DeleteGlobalRef(env, handshakeCompleteCallbackRef);
11321147
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.