This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-native.git
The following commit(s) were added to refs/heads/main by this push:
new 9a7c804af Avoid a potential crash with very long ALPN protocol names
9a7c804af is described below
commit 9a7c804afc05fdc630520eb4012ce1c4ff787862
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Aug 27 17:23:54 2026 +0100
Avoid a potential crash with very long ALPN protocol names
---
native/include/ssl_private.h | 2 +-
native/src/sslcontext.c | 5 +++--
xdocs/miscellaneous/changelog.xml | 3 +++
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/native/include/ssl_private.h b/native/include/ssl_private.h
index 514890d6f..b4e829c3a 100644
--- a/native/include/ssl_private.h
+++ b/native/include/ssl_private.h
@@ -154,7 +154,7 @@
#endif /* !defined(OPENSSL_NO_TLSEXT) && defined(SSL_set_tlsext_host_name) */
-#define MAX_ALPN_PROTO_SIZE 65535
+#define MAX_ALPN_PROTO_SIZE 255
#define SSL_SELECTOR_FAILURE_CHOOSE_MY_LAST_PROTOCOL 1
typedef struct tcn_ssl_ctxt_t tcn_ssl_ctxt_t;
diff --git a/native/src/sslcontext.c b/native/src/sslcontext.c
index c051a37ce..7d8d37d86 100644
--- a/native/src/sslcontext.c
+++ b/native/src/sslcontext.c
@@ -1051,8 +1051,9 @@ static int initProtocols(JNIEnv *e, unsigned char
**proto_data, unsigned int *pr
// Find start of buffer
unsigned char *p_data_start = p_data - (p_data_len - (1 +
proto_chars_len));
unsigned char *p_data_tmp;
- // double size
- p_data_size <<= 1;
+ // double size until sufficient space is available
+ while (p_data_len > p_data_size)
+ p_data_size <<= 1;
p_data_tmp = realloc(p_data_start, p_data_size);
if (p_data_tmp == NULL) {
// Not enough memory? Free the original buffer.
diff --git a/xdocs/miscellaneous/changelog.xml
b/xdocs/miscellaneous/changelog.xml
index e15e522ef..c4bda927c 100644
--- a/xdocs/miscellaneous/changelog.xml
+++ b/xdocs/miscellaneous/changelog.xml
@@ -72,6 +72,9 @@
<fix>
Fix a potential crash when configuring raw certificates. (markt)
</fix>
+ <fix>
+ Avoid a potential crash with very long ALPN protocol names. (markt)
+ </fix>
</changelog>
</section>
<section name="2.0.15" rtext="2026-06-15">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]