Commit de784b4910d for php
commit de784b4910d4b11d8389f1239b07a6b6b68ddd5f
Author: Jorg Sowa <jorg.sowa@gmail.com>
Date: Fri Nov 13 20:13:19 2026 +0100
Fix uninitialized $errno for unknown transport in stream_socket_client()/fsockopen() (GH-25428)
Closes GH-25428
diff --git a/NEWS b/NEWS
index 003160c8b56..7e4ec6ebde5 100644
--- a/NEWS
+++ b/NEWS
@@ -130,6 +130,8 @@ PHP NEWS
- Standard:
. Fixed bug GH-25387 (Uploaded files leak in request_parse_body()).
(Kévin Dunglas)
+ . Fixed uninitialized $errno in stream_socket_client() and fsockopen() for
+ an unknown transport. (Jorg Sowa)
- Streams:
. Fixed in-place URL decoding of interned strings in the HTTP and FTP
diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c
index 13485f9d197..61e6ccf979f 100644
--- a/ext/standard/fsock.c
+++ b/ext/standard/fsock.c
@@ -55,7 +55,7 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
struct timeval tv;
char *hashkey = NULL;
php_stream *stream = NULL;
- int err;
+ int err = 0;
char *hostname = NULL;
size_t hostname_len;
zend_string *errstr = NULL;
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index 6de7d255e06..6792db64b81 100644
--- a/ext/standard/streamsfuncs.c
+++ b/ext/standard/streamsfuncs.c
@@ -112,7 +112,7 @@ PHP_FUNCTION(stream_socket_client)
struct timeval tv;
char *hashkey = NULL;
php_stream *stream = NULL;
- int err;
+ int err = 0;
zend_long flags = PHP_STREAM_CLIENT_CONNECT;
zend_string *errstr = NULL;
php_stream_context *context = NULL;
diff --git a/ext/standard/tests/network/fsockopen_error.phpt b/ext/standard/tests/network/fsockopen_error.phpt
index 0474d21d8e4..e23fa9ba427 100644
--- a/ext/standard/tests/network/fsockopen_error.phpt
+++ b/ext/standard/tests/network/fsockopen_error.phpt
@@ -20,6 +20,7 @@
$errstr = null;
$timeout = 1.5;
var_dump( fsockopen($hostname, $port, $errno, $errstr, $timeout) );
+var_dump($errno);
var_dump($errstr);
echo "Done";
@@ -37,5 +38,6 @@
Warning: fsockopen(): Unable to connect to invalid://127.0.0.1:31337 (Unable to find the socket transport "invalid" - did you forget to enable it when you configured PHP?) in %s on line %d
bool(false)
+int(0)
string(100) "Unable to find the socket transport "invalid" - did you forget to enable it when you configured PHP?"
Done
diff --git a/ext/standard/tests/network/stream_socket_client_error.phpt b/ext/standard/tests/network/stream_socket_client_error.phpt
new file mode 100644
index 00000000000..d003c467a14
--- /dev/null
+++ b/ext/standard/tests/network/stream_socket_client_error.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test stream_socket_client() function : error conditions
+--FILE--
+<?php
+echo "*** Testing stream_socket_client() : basic error conditions ***\n";
+
+echo "\n-- Attempting to connect using an invalid protocol --\n";
+$address = 'invalid://127.0.0.1:31337';
+$errno = null;
+$errstr = null;
+$timeout = 1.5;
+var_dump( stream_socket_client($address, $errno, $errstr, $timeout) );
+var_dump($errno);
+var_dump($errstr);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing stream_socket_client() : basic error conditions ***
+
+-- Attempting to connect using an invalid protocol --
+
+Warning: stream_socket_client(): Unable to connect to invalid://127.0.0.1:31337 (Unable to find the socket transport "invalid" - did you forget to enable it when you configured PHP?) in %s on line %d
+bool(false)
+int(0)
+string(100) "Unable to find the socket transport "invalid" - did you forget to enable it when you configured PHP?"
+Done