Skip to content

Commit 3427556

Browse files
committedDec 30, 2024
Merge branch 'PHP-8.4'
* PHP-8.4: Fix FD getting code on big endian (#17259)
2 parents ecb90c1 + b4d3e4e commit 3427556

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
 

‎ext/posix/posix.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <unistd.h>
2323
#include "ext/standard/info.h"
2424
#include "php_posix.h"
25+
#include "main/php_network.h"
2526

2627
#ifdef HAVE_POSIX
2728

@@ -415,7 +416,7 @@ PHP_FUNCTION(posix_ctermid)
415416
/* }}} */
416417

417418
/* Checks if the provides resource is a stream and if it provides a file descriptor */
418-
static zend_result php_posix_stream_get_fd(zval *zfp, zend_long *fd) /* {{{ */
419+
static zend_result php_posix_stream_get_fd(zval *zfp, zend_long *ret) /* {{{ */
419420
{
420421
php_stream *stream;
421422

@@ -425,19 +426,21 @@ static zend_result php_posix_stream_get_fd(zval *zfp, zend_long *fd) /* {{{ */
425426
return FAILURE;
426427
}
427428

428-
/* get the fd.
429+
/* get the fd. php_socket_t is used for FDs, and is shorter than zend_long.
429430
* NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag when casting.
430431
* It is only used here so that the buffered data warning is not displayed.
431432
*/
433+
php_socket_t fd = -1;
432434
if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL) == SUCCESS) {
433-
php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)fd, 0);
435+
php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void**)&fd, 0);
434436
} else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL) == SUCCESS) {
435-
php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void*)fd, 0);
437+
php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void**)&fd, 0);
436438
} else {
437439
php_error_docref(NULL, E_WARNING, "Could not use stream of type '%s'",
438440
stream->ops->label);
439441
return FAILURE;
440442
}
443+
*ret = fd;
441444
return SUCCESS;
442445
}
443446
/* }}} */

0 commit comments

Comments
 (0)
Failed to load comments.