From 620bf6ccd222afe1bce534f556a7957c20f3e7a3 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Wed, 25 Nov 2026 22:57:55 +0100 Subject: [PATCH] Fix stream_socket_enable_crypto() reading the crypto_method option without a type check The option was read with Z_LVAL_P(), so a numeric string or a float gave an arbitrary method and the client never sent a ClientHello. Convert it with zval_get_long(), as the ssl:// transport does. --- ...cket_enable_crypto_method_option_type.phpt | 38 +++++++++++++++++++ ext/standard/streamsfuncs.c | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 ext/openssl/tests/stream_socket_enable_crypto_method_option_type.phpt diff --git a/ext/openssl/tests/stream_socket_enable_crypto_method_option_type.phpt b/ext/openssl/tests/stream_socket_enable_crypto_method_option_type.phpt new file mode 100644 index 000000000000..7a12ac2a2428 --- /dev/null +++ b/ext/openssl/tests/stream_socket_enable_crypto_method_option_type.phpt @@ -0,0 +1,38 @@ +--TEST-- +stream_socket_enable_crypto() coerces the "crypto_method" context option to an integer +--EXTENSIONS-- +openssl +--FILE-- + +--EXPECT-- +int(0) +string(2) "16" +int(0) +string(2) "16" +int(0) +string(2) "16" diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index d1ed12a78c3a..00af949f677f 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -1598,7 +1598,7 @@ PHP_FUNCTION(stream_socket_enable_crypto) RETURN_THROWS(); } - cryptokind = Z_LVAL_P(val); + cryptokind = zval_get_long(val); } if (zsessstream) {