Skip to content

Fix stream_socket_enable_crypto() reading the crypto_method option without a type check - #25764

Open
lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/standard-stream-crypto-method-type-PHP-8.4
Open

lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/standard-stream-crypto-method-type-PHP-8.4

Conversation

@lacatoire

@lacatoire lacatoire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

stream_socket_enable_crypto() reads the crypto_method context option with Z_LVAL_P() without a type check, so a numeric string or a float gives a garbage method. Use zval_get_long(), as the ssl:// transport does.

$listener = stream_socket_server('tcp://127.0.0.1:0');
$client = stream_socket_client('tcp://' . stream_socket_get_name($listener, false));
$server = stream_socket_accept($listener);
stream_set_timeout($server, 1);
stream_set_blocking($client, false);
stream_context_set_option($client, 'ssl', 'crypto_method', (string) STREAM_CRYPTO_METHOD_TLS_CLIENT);
stream_socket_enable_crypto($client, true);
var_dump(bin2hex(fread($server, 1)));

Before: string(0) "".
After: string(2) "16".

…thout 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant