[php-src] master: Fix php_pgsql_fd_cast() wrt. php_stream_can_cast()
| From: | Christoph M. Becker | Date: | Tue, 20 Apr 2021 16:33:41 +0000 |
| Subject: | [php-src] master: Fix php_pgsql_fd_cast() wrt. php_stream_can_cast() | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-115708@lists.php.net to get a copy of this message | ||
Author: Christoph M. Becker (cmb69)
Date: 2021-04-20T18:29:12+02:00
Commit: https://github.com/php/php-src/commit/1fcea24efb9c9b52449acb1ea907725c63480e30
Raw diff: https://github.com/php/php-src/commit/1fcea24efb9c9b52449acb1ea907725c63480e30.diff
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.
Changed paths:
M NEWS
M ext/pgsql/pgsql.c
Diff:
diff --git a/NEWS b/NEWS
index 6a1b767a6a68a..e3fac31031272 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 22e0825c54c27..f52ff884d83cd 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;
}