[php-src] PR #25561: Fix stream_socket_sendto() sending plaintext on a stream with TLS enabled

From: Date: Wed, 18 Nov 2026 15:35:10 +0000
Subject: [php-src] PR #25561: Fix stream_socket_sendto() sending plaintext on a stream with TLS enabled
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-40781@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25561 Author: lacatoire The openssl transport did not handle the send operation used by stream_socket_sendto(), so on a stream with TLS enabled the data went to the socket as plaintext, in the middle of the TLS records. The call reported success and the peer failed on its next read. The send now goes through the TLS session while encryption is active. To reproduce: ```php $key = openssl_pkey_new(['private_key_bits' => 2048]); $cert = openssl_csr_sign(openssl_csr_new(['commonName' => 'localhost'], $key), null, $key, 1); openssl_x509_export($cert, $certPem); openssl_pkey_export($key, $keyPem); $pem = tempnam(sys_get_temp_dir(), 'pem'); file_put_contents($pem, $certPem . $keyPem); $listener = stream_socket_server('tcp://127.0.0.1:0', context: stream_context_create(['ssl' => ['local_cert' => $pem]])); $client = stream_socket_client('tcp://' . stream_socket_get_name($listener, false), context: stream_context_create(['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]])); $server = stream_socket_accept($listener); stream_set_blocking($client, false); stream_set_blocking($server, false); do { $clientDone = stream_socket_enable_crypto($client, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); $serverDone = stream_socket_enable_crypto($server, true, STREAM_CRYPTO_METHOD_TLS_SERVER); } while ($clientDone === 0 || $serverDone === 0); var_dump(fwrite($client, 'ENCRYPTED')); var_dump(fread($server, 8192)); var_dump(stream_socket_sendto($client, 'SENT WITH SENDTO')); var_dump(@fread($server, 8192)); unlink($pem); ``` Before (8.4.26, 8.5.12): the last fread() returns string(0) "". After: it returns string(16) "SENT WITH SENDTO".

« previous php.git-pulls (#40781) next »