streams: Indicate which argument fails the stream ZPP check

This commit is contained in:
Gina Peter Banyard 2025-03-15 16:59:39 +00:00
parent efa9e5fdd0
commit 556e4d9008
27 changed files with 96 additions and 93 deletions

View file

@ -287,11 +287,21 @@ END_EXTERN_C()
BEGIN_EXTERN_C()
static zend_always_inline bool php_stream_zend_parse_arg_into_stream(zval *arg, php_stream **destination_stream_ptr, bool check_null)
{
static zend_always_inline bool php_stream_zend_parse_arg_into_stream(
zval *arg,
php_stream **destination_stream_ptr,
bool check_null,
uint32_t arg_num
) {
if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) {
*destination_stream_ptr = (php_stream*)zend_fetch_resource2(Z_RES_P(arg), "stream", php_file_le_stream(), php_file_le_pstream());
if (UNEXPECTED(*destination_stream_ptr == NULL)) {
zend_resource *res = Z_RES_P(arg);
/* We do not use zend_fetch_resource2() API,
* as we want to be able to specify the argument number in the type error */
if (EXPECTED(res->type == php_file_le_stream() || res->type == php_file_le_pstream())) {
*destination_stream_ptr = (php_stream*)res->ptr;
return true;
} else {
zend_argument_type_error(arg_num, "must be an open stream resource");
return false;
}
} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
@ -304,7 +314,7 @@ static zend_always_inline bool php_stream_zend_parse_arg_into_stream(zval *arg,
#define PHP_Z_PARAM_STREAM_EX(destination_stream_ptr, check_null) \
Z_PARAM_PROLOGUE(0, 0); \
if (UNEXPECTED(!php_stream_zend_parse_arg_into_stream(_arg, &destination_stream_ptr, check_null))) { \
if (UNEXPECTED(!php_stream_zend_parse_arg_into_stream(_arg, &destination_stream_ptr, check_null, _i))) { \
_error_code = ZPP_ERROR_FAILURE; \
if (!EG(exception)) { \
_expected_type = check_null ? Z_EXPECTED_RESOURCE_OR_NULL : Z_EXPECTED_RESOURCE; \