[php-src] PR #24222: Fix GH-24220: Failed listen() on a tcp:// server reported as success
| From: | mpyw | Date: | Fri, 09 Oct 2026 16:00:25 +0000 |
| Subject: | [php-src] PR #24222: Fix GH-24220: Failed listen() on a tcp:// server reported as success | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-39290@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/24222
Author: mpyw
Fixes GH-24220.
The quoted description below, and the checks it describes, were done with an LLM (Claude). I
reviewed them.
> With ext/openssl,
tcp:// streams use
> php_openssl_sockop_set_option(). Its
> STREAM_XPORT_OP_LISTEN case assigned the return value of
> php_stream_socket_ops.set_option() to
> xparam->outputs.returncode.
>
> That return value only says whether the option was handled. The result of
> listen() is what the inner call stores in
> xparam->outputs.returncode. So a failed
> listen() was reported as success, and
> stream_socket_server() returned a stream that was not listening.
>
> This keeps the result the inner call stored, and sets -1 only
> if the inner call did not handle the option.
>
> There is no test: a .phpt cannot make
> listen() fail on its own, since
> bind() fails first in the usual cases. The fix was checked by
> injecting the failure with strace, in a build of php-8.6.0RC3
> configured with --disable-all --enable-cli --with-openssl:
>
> ```sh
> strace -f -q -o /dev/null -e trace=listen -e inject=listen:error=EADDRINUSE \
> sapi/cli/php -n -r
> 'var_dump(@stream_socket_server("tcp://127.0.0.1:0"));'
> ```
>
> | | Output |
> | --- | --- |
> | Before | resource(5) of type (stream) |
> | After | bool(false) |
>
> Without the injection, both builds return a listening stream.