From 1fcea24efb9c9b52449acb1ea907725c63480e30 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 20 Apr 2021 15:51:47 +0200 Subject: [PATCH] Fix php_pgsql_fd_cast() wrt. php_stream_can_cast() `php_stream_can_cast()` forwards to `_php_stream_cast()` with `ret` set to `NULL`. `php_pgsql_fd_cast()` needs to cater to that, because otherwise the stream would report that it is not castable. This *might* fix https://bugs.php.net/73903. Closes GH-6888. --- NEWS | 3 +++ ext/pgsql/pgsql.c | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 6a1b767a6a6..e3fac310312 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,9 @@ PHP NEWS . Fixed bug #80960 (opendir() warning wrong info when failed on Windows). (cmb) +- pgsql: + . Fixed php_pgsql_fd_cast() wrt. php_stream_can_cast(). (cmb) + - SPL: . Fixed bug #80933 (SplFileObject::DROP_NEW_LINE is broken for NUL and CR). (cmb, Nikita) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 22e0825c54c..f52ff884d83 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -5418,16 +5418,17 @@ static int php_pgsql_fd_cast(php_stream *stream, int cast_as, void **ret) /* {{{ switch (cast_as) { case PHP_STREAM_AS_FD_FOR_SELECT: case PHP_STREAM_AS_FD: - case PHP_STREAM_AS_SOCKETD: - if (ret) { + case PHP_STREAM_AS_SOCKETD: { int fd_number = PQsocket(pgsql); if (fd_number == -1) { return FAILURE; } - *(php_socket_t *)ret = fd_number; - return SUCCESS; + if (ret) { + *(php_socket_t *)ret = fd_number; + } } + return SUCCESS; default: return FAILURE; }