[php-src] master: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Tue, 04 Aug 2026 06:19:50 +0000
Subject: [php-src] master: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-140462@lists.php.net to get a copy of this message
Author: ndossche (ndossche) Date: 2026-08-04T08:19:09+02:00 Commit: https://github.com/php/php-src/commit/f433660018066d330e2f2337a8e5cc09cc9b85bd Raw diff: https://github.com/php/php-src/commit/f433660018066d330e2f2337a8e5cc09cc9b85bd.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: openssl: Check return value of SSL_CTX_set_alpn_protos() (#22996) Changed paths: A ext/openssl/tests/alpn_protocols_invalid.phpt M NEWS M ext/openssl/xp_ssl.c Diff: diff --git a/NEWS b/NEWS index 5c304c5e2b14..195115821e06 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,9 @@ PHP NEWS . Fixed bug GH-22857 (Function JIT emits wrong code for FETCH_OBJ_FUNC_ARG on a property hook getter, losing register-held variables). (Zhao Hao) +- OpenSSL: + . Fix missing error check on invalid alpn protocols. (ndossche) + - MBString: . Fixed bug GH-22779 (mb_strrpos() returns the wrong position for a negative offset in a non-UTF-8 encoding). (Eyüp Can Akman) diff --git a/ext/openssl/tests/alpn_protocols_invalid.phpt b/ext/openssl/tests/alpn_protocols_invalid.phpt new file mode 100644 index 000000000000..0d35b850d198 --- /dev/null +++ b/ext/openssl/tests/alpn_protocols_invalid.phpt @@ -0,0 +1,49 @@ +--TEST-- +Setting an invalid TLS ALPN protocol list on a client stream fails +--EXTENSIONS-- +openssl +--SKIPIF-- +<?php +if (OPENSSL_VERSION_NUMBER < 0x30000000) die('skip For OpenSSL >= 3.0'); +?> +--FILE-- +<?php +$server = stream_socket_server('tcp://127.0.0.1:0', $errno, $errstr); +$address = stream_socket_get_name($server, false); + +function try_alpn($protocols, $streamOptions): void { + global $address; + + $context = stream_context_create([ + 'ssl' => ['alpn_protocols' => $protocols, 'verify_peer' => false], + 'stream' => $streamOptions, + ]); + $client = stream_socket_client("tcp://$address", $errno, $errstr, 1, STREAM_CLIENT_CONNECT, $context); + var_dump(stream_socket_enable_crypto($client, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)); + fclose($client); +} + +foreach (['', ',', 'h2,', ',h2', 'h2,,http/1.1'] as $protocols) { + try_alpn($protocols, []); +} + +try_alpn('', []); +?> +--EXPECTF-- +Warning: stream_socket_enable_crypto(): Failed setting TLS ALPN protocols, protocol names must not be empty in %s on line %d +bool(false) + +Warning: stream_socket_enable_crypto(): Failed setting TLS ALPN protocols, protocol names must not be empty in %s on line %d +bool(false) + +Warning: stream_socket_enable_crypto(): Failed setting TLS ALPN protocols, protocol names must not be empty in %s on line %d +bool(false) + +Warning: stream_socket_enable_crypto(): Failed setting TLS ALPN protocols, protocol names must not be empty in %s on line %d +bool(false) + +Warning: stream_socket_enable_crypto(): Failed setting TLS ALPN protocols, protocol names must not be empty in %s on line %d +bool(false) + +Warning: stream_socket_enable_crypto(): Failed setting TLS ALPN protocols, protocol names must not be empty in %s on line %d +bool(false) diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index cab8f9c859b4..1398c2e23fe8 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -1658,7 +1658,13 @@ static zend_result php_openssl_setup_crypto(php_stream *stream, return FAILURE; } if (sslsock->is_client) { - SSL_CTX_set_alpn_protos(sslsock->ctx, alpn, alpn_len); + if (SSL_CTX_set_alpn_protos(sslsock->ctx, alpn, alpn_len)) { + php_error_docref(NULL, E_WARNING, "Failed setting TLS ALPN protocols, protocol names must not be empty"); + efree(alpn); + SSL_CTX_free(sslsock->ctx); + sslsock->ctx = NULL; + return FAILURE; + } } else { sslsock->alpn_ctx.data = (unsigned char *) pestrndup((const char*)alpn, alpn_len, php_stream_is_persistent(stream)); sslsock->alpn_ctx.len = alpn_len;

« previous php.cvs (#140462) next »