[php-src] master: Fix uninitialized $errno for unknown transport in stream_socket_client()/fsockopen() (GH-25428)

From: Date: Fri, 13 Nov 2026 19:47:55 +0000
Subject: [php-src] master: Fix uninitialized $errno for unknown transport in stream_socket_client()/fsockopen() (GH-25428)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143687@lists.php.net to get a copy of this message
Author: Jorg Sowa (jorgsowa) Date: 2026-11-13T20:13:19+01:00 Commit: https://github.com/php/php-src/commit/de784b4910d4b11d8389f1239b07a6b6b68ddd5f Raw diff: https://github.com/php/php-src/commit/de784b4910d4b11d8389f1239b07a6b6b68ddd5f.diff Fix uninitialized $errno for unknown transport in stream_socket_client()/fsockopen() (GH-25428) Closes GH-25428 Changed paths: A ext/standard/tests/network/stream_socket_client_error.phpt M NEWS M ext/standard/fsock.c M ext/standard/streamsfuncs.c M ext/standard/tests/network/fsockopen_error.phpt Diff: diff --git a/NEWS b/NEWS index 003160c8b56f..7e4ec6ebde54 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 13485f9d1977..61e6ccf979fe 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 6de7d255e067..6792db64b817 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 0474d21d8e42..e23fa9ba4273 100644 --- a/ext/standard/tests/network/fsockopen_error.phpt +++ b/ext/standard/tests/network/fsockopen_error.phpt @@ -20,6 +20,7 @@ $errno = null; $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 @@ string(%d) "%a" 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 000000000000..d003c467a143 --- /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

« previous php.cvs (#143687) next »