Commit a203fe4920a for php.net

commit a203fe4920a25088eea20b00ddfa93b8a845a7d9
Author: Weilin Du <weilindu@php.net>
Date:   Fri Sep 4 21:36:30 2026 +0800

    ext/openssl: Fix remaining OpenSSL test races (#23565)

    Use unique temporary file names for tests that may run concurrently,
    remove a CLEAN section that deletes another test's file, and replace
    fixed server ports with ephemeral ports.

diff --git a/ext/openssl/tests/ServerClientTestCase.inc b/ext/openssl/tests/ServerClientTestCase.inc
index b7e866954fc..0c3c49db725 100644
--- a/ext/openssl/tests/ServerClientTestCase.inc
+++ b/ext/openssl/tests/ServerClientTestCase.inc
@@ -24,7 +24,7 @@ function phpt_has_sslv3() {
     if (!is_null($result)) {
         return $result;
     }
-    $server = @stream_socket_server('sslv3://127.0.0.1:10013');
+    $server = @stream_socket_server('sslv3://127.0.0.1:0');
     if ($result = !!$server) {
         fclose($server);
     }
diff --git a/ext/openssl/tests/gh20802.phpt b/ext/openssl/tests/gh20802.phpt
index 786679c41c6..e078f461fc4 100644
--- a/ext/openssl/tests/gh20802.phpt
+++ b/ext/openssl/tests/gh20802.phpt
@@ -26,7 +26,7 @@ class A {};
 		    ]
 	    ]
     ]);
-    $server = stream_socket_server('tls://127.0.0.1:12443', $errno, $errstr, $flags, $ctx);
+    $server = stream_socket_server('tls://127.0.0.1:0', $errno, $errstr, $flags, $ctx);
     phpt_notify_server_start($server);
     stream_socket_accept($server, 3);
 CODE;
@@ -42,7 +42,7 @@ class A {};
 	    'verify_peer'  => false
 	]
     ]);
-    @stream_socket_client("tls://127.0.0.1:12443", $errno, $errstr, 1, $flags, $ctx);
+    @stream_socket_client("tls://{{ ADDR }}", $errno, $errstr, 1, $flags, $ctx);
 CODE;

 include 'CertificateGenerator.inc';
diff --git a/ext/openssl/tests/openssl_error_string_basic_openssl3.phpt b/ext/openssl/tests/openssl_error_string_basic_openssl3.phpt
index 093681cb2e1..d36fcac194e 100644
--- a/ext/openssl/tests/openssl_error_string_basic_openssl3.phpt
+++ b/ext/openssl/tests/openssl_error_string_basic_openssl3.phpt
@@ -53,7 +53,7 @@ function dump_openssl_errors($name) {
 }

 // common output file
-$output_file =  __DIR__ . "/openssl_error_string_basic_output.tmp";
+$output_file =  __DIR__ . "/openssl_error_string_basic_openssl3_output.tmp";
 // invalid file for read is something that does not exist in current directory
 $invalid_file_for_read = __DIR__ . "/invalid_file_for_read_operation.txt";
 // invalid file for is the test dir as writing file to existing dir should always fail
@@ -156,7 +156,7 @@ function dump_openssl_errors($name) {
 ?>
 --CLEAN--
 <?php
-$output_file =  __DIR__ . "/openssl_error_string_basic_output.tmp";
+$output_file =  __DIR__ . "/openssl_error_string_basic_openssl3_output.tmp";
 if (is_file($output_file)) {
     unlink($output_file);
 }
diff --git a/ext/openssl/tests/openssl_pkcs12_export_to_file_basic.phpt b/ext/openssl/tests/openssl_pkcs12_export_to_file_basic.phpt
index f53e9753613..0938921a8ff 100644
--- a/ext/openssl/tests/openssl_pkcs12_export_to_file_basic.phpt
+++ b/ext/openssl/tests/openssl_pkcs12_export_to_file_basic.phpt
@@ -4,7 +4,7 @@
 openssl
 --FILE--
 <?php
-$pkcsfile = __DIR__ . "/openssl_pkcs12_export_to_file__pkcsfile.tmp";
+$pkcsfile = __DIR__ . "/openssl_pkcs12_export_to_file_basic__pkcsfile.tmp";

 $cert_file = __DIR__ . "/public.crt";
 $cert = file_get_contents($cert_file);
@@ -38,7 +38,7 @@
 ?>
 --CLEAN--
 <?php
-$pkcsfile = __DIR__ . "/openssl_pkcs12_export_to_file__pkcsfile.tmp";
+$pkcsfile = __DIR__ . "/openssl_pkcs12_export_to_file_basic__pkcsfile.tmp";
 if (file_exists($pkcsfile)) {
     unlink($pkcsfile);
 }
diff --git a/ext/openssl/tests/openssl_pkcs12_export_to_file_error.phpt b/ext/openssl/tests/openssl_pkcs12_export_to_file_error.phpt
index d98f6d15fef..fab11c672f2 100644
--- a/ext/openssl/tests/openssl_pkcs12_export_to_file_error.phpt
+++ b/ext/openssl/tests/openssl_pkcs12_export_to_file_error.phpt
@@ -4,7 +4,7 @@
 openssl
 --FILE--
 <?php
-$pkcsfile = __DIR__ . "/openssl_pkcs12_export_to_file__pkcsfile.tmp";
+$pkcsfile = __DIR__ . "/openssl_pkcs12_export_to_file_error__pkcsfile.tmp";

 $cert_file = __DIR__ . "/public.crt";
 $cert = file_get_contents($cert_file);
@@ -21,7 +21,7 @@
 ?>
 --CLEAN--
 <?php
-$pkcsfile = __DIR__ . "/openssl_pkcs12_export_to_file__pkcsfile.tmp";
+$pkcsfile = __DIR__ . "/openssl_pkcs12_export_to_file_error__pkcsfile.tmp";
 if (file_exists($pkcsfile)) {
     unlink($pkcsfile);
 }
diff --git a/ext/openssl/tests/session_resumption_import_export_session.phpt b/ext/openssl/tests/session_resumption_import_export_session.phpt
index 0d9a3274b11..9c1f40fc88b 100644
--- a/ext/openssl/tests/session_resumption_import_export_session.phpt
+++ b/ext/openssl/tests/session_resumption_import_export_session.phpt
@@ -8,7 +8,7 @@
 ?>
 --FILE--
 <?php
-$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_resumption_serialize.pem.tmp';
+$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_resumption_import_export.pem.tmp';

 $serverCode = <<<'CODE'
     $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN;
@@ -76,7 +76,7 @@
 ?>
 --CLEAN--
 <?php
-@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'session_resumption_serialize.pem.tmp');
+@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'session_resumption_import_export.pem.tmp');
 ?>
 --EXPECTF--
 string(%d) "-----BEGIN SSL SESSION PARAMETERS-----
diff --git a/ext/openssl/tests/session_resumption_invalid_session_import.phpt b/ext/openssl/tests/session_resumption_invalid_session_import.phpt
index a9c5b65f205..efd49e7c693 100644
--- a/ext/openssl/tests/session_resumption_invalid_session_import.phpt
+++ b/ext/openssl/tests/session_resumption_invalid_session_import.phpt
@@ -15,9 +15,5 @@
     echo $e->getMessage() . "\n";
 }
 ?>
---CLEAN--
-<?php
-@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'session_cache_disabled.pem.tmp');
-?>
 --EXPECT--
 Failed to import session data
diff --git a/ext/openssl/tests/session_resumption_serialize_session.phpt b/ext/openssl/tests/session_resumption_serialize_session.phpt
index f2f3c98e5e5..ca43c46c390 100644
--- a/ext/openssl/tests/session_resumption_serialize_session.phpt
+++ b/ext/openssl/tests/session_resumption_serialize_session.phpt
@@ -8,7 +8,7 @@
 ?>
 --FILE--
 <?php
-$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_resumption_serialize.pem.tmp';
+$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_resumption_serialize_session.pem.tmp';

 $serverCode = <<<'CODE'
     $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN;
@@ -68,7 +68,7 @@
 ?>
 --CLEAN--
 <?php
-@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'session_resumption_serialize.pem.tmp');
+@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'session_resumption_serialize_session.pem.tmp');
 ?>
 --EXPECTF--
 string(%d) "O:15:"Openssl\Session":1:{s:3:"pem";s:%d:"-----BEGIN SSL SESSION PARAMETERS-----
diff --git a/ext/openssl/tests/session_resumption_server_external_with_context_id.phpt b/ext/openssl/tests/session_resumption_server_external_with_context_id.phpt
index 02c6a7dcfdc..f8aa9ce3305 100644
--- a/ext/openssl/tests/session_resumption_server_external_with_context_id.phpt
+++ b/ext/openssl/tests/session_resumption_server_external_with_context_id.phpt
@@ -8,7 +8,7 @@
 ?>
 --FILE--
 <?php
-$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_external_proper.pem.tmp';
+$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_external_context_id.pem.tmp';

 $serverCode = <<<'CODE'
     $sessionStore = [];
@@ -105,7 +105,7 @@
 ?>
 --CLEAN--
 <?php
-@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'session_external_proper.pem.tmp');
+@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'session_external_context_id.pem.tmp');
 ?>
 --EXPECTF--
 Client first connection resumed: no
diff --git a/ext/openssl/tests/session_resumption_server_external_with_context_id_tls12.phpt b/ext/openssl/tests/session_resumption_server_external_with_context_id_tls12.phpt
index bdc3d2ce1bf..7b4d8bfa5a9 100644
--- a/ext/openssl/tests/session_resumption_server_external_with_context_id_tls12.phpt
+++ b/ext/openssl/tests/session_resumption_server_external_with_context_id_tls12.phpt
@@ -8,7 +8,7 @@
 ?>
 --FILE--
 <?php
-$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_external_proper.pem.tmp';
+$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_external_context_id_tls12.pem.tmp';

 $serverCode = <<<'CODE'
     $sessionStore = [];
@@ -105,7 +105,7 @@
 ?>
 --CLEAN--
 <?php
-@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'session_external_proper.pem.tmp');
+@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'session_external_context_id_tls12.pem.tmp');
 ?>
 --EXPECTF--
 Client first connection resumed: no
diff --git a/ext/openssl/tests/stream_server_reneg_limit.phpt b/ext/openssl/tests/stream_server_reneg_limit.phpt
index d84906c81ca..b8e7c172673 100644
--- a/ext/openssl/tests/stream_server_reneg_limit.phpt
+++ b/ext/openssl/tests/stream_server_reneg_limit.phpt
@@ -25,7 +25,7 @@

 $serverCode = <<<'CODE'
     $printed = false;
-    $serverUri = "ssl://127.0.0.1:64321";
+    $serverUri = "ssl://127.0.0.1:0";
     $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
     $serverCtx = stream_context_create(['ssl' => [
         'local_cert' => '%s',
@@ -42,7 +42,7 @@
     ]]);

     $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
-    phpt_notify();
+    phpt_notify(message: stream_socket_get_name($server, false));

     $clients = [];
     while (1) {
@@ -71,9 +71,9 @@
 $serverCode = sprintf($serverCode, $certFile);

 $clientCode = <<<'CODE'
-    phpt_wait();
+    $serverUri = trim(phpt_wait());

-    $cmd = 'openssl s_client -connect 127.0.0.1:64321';
+    $cmd = 'openssl s_client -connect ' . escapeshellarg($serverUri);
     $descriptorSpec = [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]];
     $process = proc_open($cmd, $descriptorSpec, $pipes);