From: Matt Caswell Date: Fri, 31 May 2024 10:18:27 +0000 (+0100) Subject: More correctly handle a selected_len of 0 when processing NPN X-Git-Tag: openssl-3.3.2~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c015a9dcb0e0e5edf2d870181a6c9ba9a1305722;p=thirdparty%2Fopenssl.git More correctly handle a selected_len of 0 when processing NPN In the case where the NPN callback returns with SSL_TLEXT_ERR_OK, but the selected_len is 0 we should fail. Previously this would fail with an internal_error alert because calling OPENSSL_malloc(selected_len) will return NULL when selected_len is 0. We make this error detection more explicit and return a handshake failure alert. Follow on from CVE-2024-5535 Reviewed-by: Tomas Mraz Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/24716) (cherry picked from commit c6e1ea223510bb7104bf0c41c0c45eda5a16b718) --- diff --git a/ssl/statem/extensions_clnt.c b/ssl/statem/extensions_clnt.c index 381a6c9d7b9..1ab3c13d570 100644 --- a/ssl/statem/extensions_clnt.c +++ b/ssl/statem/extensions_clnt.c @@ -1560,8 +1560,8 @@ int tls_parse_stoc_npn(SSL_CONNECTION *s, PACKET *pkt, unsigned int context, if (sctx->ext.npn_select_cb(SSL_CONNECTION_GET_SSL(s), &selected, &selected_len, PACKET_data(pkt), PACKET_remaining(pkt), - sctx->ext.npn_select_cb_arg) != - SSL_TLSEXT_ERR_OK) { + sctx->ext.npn_select_cb_arg) != SSL_TLSEXT_ERR_OK + || selected_len == 0) { SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE, SSL_R_BAD_EXTENSION); return 0; }