From b67f59ba2a612af9e4d863450516f297d6337682 Mon Sep 17 00:00:00 2001 From: haszi Date: Sun, 7 Jan 2024 22:16:26 +0100 Subject: [PATCH 1/5] Clear handler status flag in handler init --- main/output.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/output.c b/main/output.c index 76d4e7709e846..1a760bf903256 100644 --- a/main/output.c +++ b/main/output.c @@ -478,7 +478,7 @@ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, default: user = ecalloc(1, sizeof(php_output_handler_user_func_t)); if (SUCCESS == zend_fcall_info_init(output_handler, 0, &user->fci, &user->fcc, &handler_name, &error)) { - handler = php_output_handler_init(handler_name, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_USER); + handler = php_output_handler_init(handler_name, chunk_size, (flags & ~0xf00f) | PHP_OUTPUT_HANDLER_USER); ZVAL_COPY(&user->zoh, output_handler); handler->func.user = user; } else { @@ -504,7 +504,7 @@ PHPAPI php_output_handler *php_output_handler_create_internal(const char *name, php_output_handler *handler; zend_string *str = zend_string_init(name, name_len, 0); - handler = php_output_handler_init(str, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_INTERNAL); + handler = php_output_handler_init(str, chunk_size, (flags & ~0xf00f) | PHP_OUTPUT_HANDLER_INTERNAL); handler->func.internal = output_handler; zend_string_release_ex(str, 0); From 283f0133c428f5432f8a119effebf20c3cda10db Mon Sep 17 00:00:00 2001 From: haszi Date: Wed, 10 Jan 2024 12:20:45 +0100 Subject: [PATCH 2/5] Change flags clearing to a macro function --- main/output.c | 4 ++-- main/php_output.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/main/output.c b/main/output.c index 1a760bf903256..2c2c13b672aaf 100644 --- a/main/output.c +++ b/main/output.c @@ -478,7 +478,7 @@ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, default: user = ecalloc(1, sizeof(php_output_handler_user_func_t)); if (SUCCESS == zend_fcall_info_init(output_handler, 0, &user->fci, &user->fcc, &handler_name, &error)) { - handler = php_output_handler_init(handler_name, chunk_size, (flags & ~0xf00f) | PHP_OUTPUT_HANDLER_USER); + handler = php_output_handler_init(handler_name, chunk_size, PHP_OUTPUT_HANDLER_ABILITY_FLAGS(flags) | PHP_OUTPUT_HANDLER_USER); ZVAL_COPY(&user->zoh, output_handler); handler->func.user = user; } else { @@ -504,7 +504,7 @@ PHPAPI php_output_handler *php_output_handler_create_internal(const char *name, php_output_handler *handler; zend_string *str = zend_string_init(name, name_len, 0); - handler = php_output_handler_init(str, chunk_size, (flags & ~0xf00f) | PHP_OUTPUT_HANDLER_INTERNAL); + handler = php_output_handler_init(str, chunk_size, PHP_OUTPUT_HANDLER_ABILITY_FLAGS(flags) | PHP_OUTPUT_HANDLER_INTERNAL); handler->func.internal = output_handler; zend_string_release_ex(str, 0); diff --git a/main/php_output.h b/main/php_output.h index 852aab7fb9db0..d722eba953b47 100644 --- a/main/php_output.h +++ b/main/php_output.h @@ -43,6 +43,8 @@ #define PHP_OUTPUT_HANDLER_DISABLED 0x2000 #define PHP_OUTPUT_HANDLER_PROCESSED 0x4000 +#define PHP_OUTPUT_HANDLER_ABILITY_FLAGS(bitmask) ((bitmask) & ~0xf00f) + /* handler op return values */ typedef enum _php_output_handler_status_t { PHP_OUTPUT_HANDLER_FAILURE, From e05a75e366a696d7b1eaf26cc645dea399ab7898 Mon Sep 17 00:00:00 2001 From: haszi Date: Wed, 10 Jan 2024 12:21:42 +0100 Subject: [PATCH 3/5] Add status flag erasure test --- tests/output/ob_start_flags.phpt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/output/ob_start_flags.phpt diff --git a/tests/output/ob_start_flags.phpt b/tests/output/ob_start_flags.phpt new file mode 100644 index 0000000000000..2fce4ea120c21 --- /dev/null +++ b/tests/output/ob_start_flags.phpt @@ -0,0 +1,30 @@ +--TEST-- +ob_start(): Ensure that user supplied handler type and status flags are erased +--FILE-- + +--EXPECT-- +int(112) +int(0) +int(0) +int(0) +int(0) From ab50258b84360ca01c74dddcc68ffecc818cc725 Mon Sep 17 00:00:00 2001 From: haszi Date: Fri, 12 Jan 2024 22:05:55 +0100 Subject: [PATCH 4/5] Update handler type in test --- tests/output/ob_start_flags.phpt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/output/ob_start_flags.phpt b/tests/output/ob_start_flags.phpt index 2fce4ea120c21..a52ced6bd10a7 100644 --- a/tests/output/ob_start_flags.phpt +++ b/tests/output/ob_start_flags.phpt @@ -2,13 +2,14 @@ ob_start(): Ensure that user supplied handler type and status flags are erased --FILE-- $s, 0, PHP_OUTPUT_HANDLER_STDFLAGS | - PHP_OUTOPUT_HANDLER_TYPE_INTERNAL | + PHP_OUTPUT_HANDLER_TYPE_INTERNAL | PHP_OUTPUT_HANDLER_STARTED | PHP_OUTPUT_HANDLER_DISABLED | PHP_OUTPUT_HANDLER_PROCESSED @@ -17,14 +18,14 @@ ob_start( $bitmask = ob_get_status()['flags']; var_dump($bitmask & PHP_OUTPUT_HANDLER_STDFLAGS); -var_dump($bitmask & PHP_OUTOPUT_HANDLER_TYPE_INTERNAL); +var_dump($bitmask & PHP_OUTPUT_HANDLER_TYPE_USER); var_dump($bitmask & PHP_OUTPUT_HANDLER_STARTED); var_dump($bitmask & PHP_OUTPUT_HANDLER_DISABLED); var_dump($bitmask & PHP_OUTPUT_HANDLER_PROCESSED); ?> --EXPECT-- int(112) -int(0) +int(1) int(0) int(0) int(0) From ef76c10b339d38f11a2e57c90d27652239102cca Mon Sep 17 00:00:00 2001 From: haszi Date: Fri, 12 Jan 2024 22:14:08 +0100 Subject: [PATCH 5/5] UPGRADING --- UPGRADING | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/UPGRADING b/UPGRADING index 7ccc9751c0d09..776f729c43a30 100644 --- a/UPGRADING +++ b/UPGRADING @@ -237,6 +237,10 @@ PHP 8.4 UPGRADE NOTES . New serial_hex parameter added to openssl_csr_sign to allow setting serial number in the hexadecimal format. +- Output Buffering Control: + . Output handler status flags passed to the flags parameter of ob_start + are now cleared. + - PDO: . getAttribute, enabled to get the value of ATTR_STRINGIFY_FETCHES.