From 6a9e11162c65cc58a6511d127d5f506f863affcc Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 1 Oct 2026 16:15:37 -0300 Subject: [PATCH 1/5] sapi: remove default post reader There is only one of these; there's no point in the indirection here as it is never overrode, and set very early in main.c. Move the default post handling into the SAPI handling, and remove the pointless check if a default POST reader exists. This stuff was originally introduced in 98d95dd88eec996ad2608b357dd03bc7930b3fb4. --- main/SAPI.c | 25 +++++-------------------- main/SAPI.h | 4 ---- main/php_content_types.c | 13 ------------- main/php_content_types.h | 1 - 4 files changed, 5 insertions(+), 38 deletions(-) diff --git a/main/SAPI.c b/main/SAPI.c index 51997c041760..242fe18cd0bc 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -177,13 +177,6 @@ SAPI_API void sapi_read_post_data(void) } else { /* fallback */ SG(request_info).post_entry = NULL; - if (UNEXPECTED(!sapi_module.default_post_reader)) { - /* this should not happen as there should always be a default_post_reader */ - SG(request_info).content_type_dup = NULL; - sapi_module.sapi_error(E_WARNING, "Unsupported content type: '%s'", content_type); - efree(content_type); - return; - } } if (oldchar) { *(p-1) = oldchar; @@ -196,8 +189,11 @@ SAPI_API void sapi_read_post_data(void) post_reader_func(); } - if(sapi_module.default_post_reader) { - sapi_module.default_post_reader(); + if (!strcmp(SG(request_info).request_method, "POST")) { + if (NULL == SG(request_info).post_entry) { + /* no post handler registered, so we just swallow the data */ + sapi_read_standard_form_data(); + } } } @@ -956,17 +952,6 @@ SAPI_API void sapi_unregister_post_entry(const sapi_post_entry *post_entry) post_entry->content_type_len); } - -SAPI_API zend_result sapi_register_default_post_reader(void (*default_post_reader)(void)) -{ - if (SG(sapi_started) && EG(current_execute_data)) { - return FAILURE; - } - sapi_module.default_post_reader = default_post_reader; - return SUCCESS; -} - - SAPI_API zend_result sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray)) { if (SG(sapi_started) && EG(current_execute_data)) { diff --git a/main/SAPI.h b/main/SAPI.h index 3d7f662b30f4..236fb298db18 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -211,7 +211,6 @@ SAPI_API size_t sapi_read_post_block(char *buffer, size_t buflen); SAPI_API zend_result sapi_register_post_entries(const sapi_post_entry *post_entry); SAPI_API zend_result sapi_register_post_entry(const sapi_post_entry *post_entry); SAPI_API void sapi_unregister_post_entry(const sapi_post_entry *post_entry); -SAPI_API zend_result sapi_register_default_post_reader(void (*default_post_reader)(void)); SAPI_API zend_result sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray)); SAPI_API zend_result sapi_register_input_filter(unsigned int (*input_filter)(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len), unsigned int (*input_filter_init)(void)); @@ -257,7 +256,6 @@ struct _sapi_module_struct { char *php_ini_path_override; - void (*default_post_reader)(void); void (*treat_data)(int arg, char *str, zval *destArray); char *executable_location; @@ -303,14 +301,12 @@ struct _sapi_post_entry { BEGIN_EXTERN_C() SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data); -SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader); SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data); SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter); END_EXTERN_C() #define STANDARD_SAPI_MODULE_PROPERTIES \ NULL, /* php_ini_path_override */ \ - NULL, /* default_post_reader */ \ NULL, /* treat_data */ \ NULL, /* executable_location */ \ 0, /* php_ini_ignore */ \ diff --git a/main/php_content_types.c b/main/php_content_types.c index c727d0ed3314..63c8d14e3131 100644 --- a/main/php_content_types.c +++ b/main/php_content_types.c @@ -24,22 +24,9 @@ static const sapi_post_entry php_post_entries[] = { }; /* }}} */ -/* {{{ SAPI_POST_READER_FUNC */ -SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader) -{ - if (!strcmp(SG(request_info).request_method, "POST")) { - if (NULL == SG(request_info).post_entry) { - /* no post handler registered, so we just swallow the data */ - sapi_read_standard_form_data(); - } - } -} -/* }}} */ - /* {{{ php_startup_sapi_content_types */ int php_startup_sapi_content_types(void) { - sapi_register_default_post_reader(php_default_post_reader); sapi_register_treat_data(php_default_treat_data); sapi_register_input_filter(php_default_input_filter, NULL); return SUCCESS; diff --git a/main/php_content_types.h b/main/php_content_types.h index e734bb1963cd..6e9beed25fc9 100644 --- a/main/php_content_types.h +++ b/main/php_content_types.h @@ -15,7 +15,6 @@ #define DEFAULT_POST_CONTENT_TYPE "application/x-www-form-urlencoded" -SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader); SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); int php_startup_sapi_content_types(void); int php_setup_sapi_content_types(void); From 3826b9301ab86ba1c73731ee59ce0093dab7f859 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 1 Oct 2026 16:45:20 -0300 Subject: [PATCH 2/5] sapi: move default php_post_entries into SAPI.c mbstring had a duplicate of this; remove some indirection and provide this as a symbol so it can be switched back to w/o duplication. --- ext/mbstring/mbstring.c | 8 -------- main/SAPI.c | 9 ++++++++- main/SAPI.h | 5 +++++ main/php_content_types.c | 17 ----------------- main/php_content_types.h | 1 - 5 files changed, 13 insertions(+), 27 deletions(-) diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 1fbb9e524150..ccddec461a16 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -208,14 +208,6 @@ zend_module_entry mbstring_module_entry = { }; /* }}} */ -/* {{{ static sapi_post_entry php_post_entries[] */ -static const sapi_post_entry php_post_entries[] = { - { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_std_post_handler }, - { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL, rfc1867_post_handler }, - { NULL, 0, NULL, NULL } -}; -/* }}} */ - #ifdef COMPILE_DL_MBSTRING #ifdef ZTS ZEND_TSRMLS_CACHE_DEFINE() diff --git a/main/SAPI.c b/main/SAPI.c index 242fe18cd0bc..b77e060eda84 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -51,7 +51,7 @@ static void sapi_globals_ctor(sapi_globals_struct *sapi_globals) { memset(sapi_globals, 0, sizeof(*sapi_globals)); zend_hash_init(&sapi_globals->known_post_content_types, 8, NULL, _type_dtor, 1); - php_setup_sapi_content_types(); + sapi_register_post_entries(php_post_entries); } static void sapi_globals_dtor(sapi_globals_struct *sapi_globals) @@ -914,6 +914,13 @@ SAPI_API zend_result sapi_send_headers(void) return ret; } +/* {{{ php_post_entries[] */ +const sapi_post_entry php_post_entries[] = { + { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_std_post_handler }, + { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL, rfc1867_post_handler }, + { NULL, 0, NULL, NULL } +}; +/* }}} */ SAPI_API zend_result sapi_register_post_entries(const sapi_post_entry *post_entries) { diff --git a/main/SAPI.h b/main/SAPI.h index 236fb298db18..4e019c2513df 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -281,6 +281,11 @@ struct _sapi_post_entry { void (*post_handler)(char *content_type_dup, void *arg); }; +BEGIN_EXTERN_C() +/* Default POST entries to switch back to when overrode */ +extern SAPI_API const sapi_post_entry php_post_entries[]; +END_EXTERN_C() + /* header_handler() constants */ #define SAPI_HEADER_ADD (1<<0) diff --git a/main/php_content_types.c b/main/php_content_types.c index 63c8d14e3131..1f7f02d52964 100644 --- a/main/php_content_types.c +++ b/main/php_content_types.c @@ -16,14 +16,6 @@ #include "php_content_types.h" -/* {{{ php_post_entries[] */ -static const sapi_post_entry php_post_entries[] = { - { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_std_post_handler }, - { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL, rfc1867_post_handler }, - { NULL, 0, NULL, NULL } -}; -/* }}} */ - /* {{{ php_startup_sapi_content_types */ int php_startup_sapi_content_types(void) { @@ -32,12 +24,3 @@ int php_startup_sapi_content_types(void) return SUCCESS; } /* }}} */ - -/* {{{ php_setup_sapi_content_types */ -int php_setup_sapi_content_types(void) -{ - sapi_register_post_entries(php_post_entries); - - return SUCCESS; -} -/* }}} */ diff --git a/main/php_content_types.h b/main/php_content_types.h index 6e9beed25fc9..85a7b5323170 100644 --- a/main/php_content_types.h +++ b/main/php_content_types.h @@ -17,6 +17,5 @@ SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); int php_startup_sapi_content_types(void); -int php_setup_sapi_content_types(void); #endif /* PHP_CONTENT_TYPES_H */ From 25abe20a3ae2334f9b7259422f0cf62940b9d86a Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 1 Oct 2026 16:55:38 -0300 Subject: [PATCH 3/5] sapi: Move DEFAULT_POST_CONTENT_TYPE into SAPI.h --- main/SAPI.h | 2 ++ main/php_content_types.h | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/SAPI.h b/main/SAPI.h index 4e019c2513df..64ee19b76a91 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -304,6 +304,8 @@ END_EXTERN_C() #define SAPI_TREAT_DATA_FUNC(treat_data) void treat_data(int arg, char *str, zval* destArray) #define SAPI_INPUT_FILTER_FUNC(input_filter) unsigned int input_filter(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len) +#define DEFAULT_POST_CONTENT_TYPE "application/x-www-form-urlencoded" + BEGIN_EXTERN_C() SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data); SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data); diff --git a/main/php_content_types.h b/main/php_content_types.h index 85a7b5323170..6212de00ee71 100644 --- a/main/php_content_types.h +++ b/main/php_content_types.h @@ -13,8 +13,6 @@ #ifndef PHP_CONTENT_TYPES_H #define PHP_CONTENT_TYPES_H -#define DEFAULT_POST_CONTENT_TYPE "application/x-www-form-urlencoded" - SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); int php_startup_sapi_content_types(void); From 611c0a9a15b918995e3df454bc666604aa456049 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 1 Oct 2026 16:56:31 -0300 Subject: [PATCH 4/5] sapi: Remove indirection for treat data/input filter init --- main/main.c | 4 +++- main/php_content_types.c | 8 -------- main/php_content_types.h | 1 - 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/main/main.c b/main/main.c index aed44e60c28e..a12af698dfd1 100644 --- a/main/main.c +++ b/main/main.c @@ -2275,7 +2275,9 @@ zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additi zuv.html_errors = 1; php_startup_auto_globals(); zend_set_utility_values(&zuv); - php_startup_sapi_content_types(); + + sapi_register_treat_data(php_default_treat_data); + sapi_register_input_filter(php_default_input_filter, NULL); /* Begin to fingerprint the process state */ zend_startup_system_id(); diff --git a/main/php_content_types.c b/main/php_content_types.c index 1f7f02d52964..5df0148cb69b 100644 --- a/main/php_content_types.c +++ b/main/php_content_types.c @@ -16,11 +16,3 @@ #include "php_content_types.h" -/* {{{ php_startup_sapi_content_types */ -int php_startup_sapi_content_types(void) -{ - sapi_register_treat_data(php_default_treat_data); - sapi_register_input_filter(php_default_input_filter, NULL); - return SUCCESS; -} -/* }}} */ diff --git a/main/php_content_types.h b/main/php_content_types.h index 6212de00ee71..e05b5161d3b4 100644 --- a/main/php_content_types.h +++ b/main/php_content_types.h @@ -14,6 +14,5 @@ #define PHP_CONTENT_TYPES_H SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); -int php_startup_sapi_content_types(void); #endif /* PHP_CONTENT_TYPES_H */ From 2f851907dec4b197f78a2cf37589769a901f094c Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 1 Oct 2026 17:02:28 -0300 Subject: [PATCH 5/5] sapi: Eliminate php_content_types All its contents have been folded elsewhere. XXX: Perhaps php_std_post_handler belongs in php_variables.h? --- configure.ac | 1 - ext/mbstring/mbstring.c | 1 - main/SAPI.c | 2 -- main/SAPI.h | 1 + main/main.c | 1 - main/php_content_types.c | 18 ------------------ main/php_content_types.h | 18 ------------------ main/php_variables.c | 1 - win32/build/config.w32 | 2 +- 9 files changed, 2 insertions(+), 43 deletions(-) delete mode 100644 main/php_content_types.c delete mode 100644 main/php_content_types.h diff --git a/configure.ac b/configure.ac index f48f1e8de90e..e2a4c295a32d 100644 --- a/configure.ac +++ b/configure.ac @@ -1650,7 +1650,6 @@ PHP_ADD_SOURCES([main], m4_normalize([ main.c network.c output.c - php_content_types.c php_ini_builder.c php_ini.c php_glob.c diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index ccddec461a16..6dc28ccb3391 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -46,7 +46,6 @@ #include "php_globals.h" #include "rfc1867.h" -#include "php_content_types.h" #include "SAPI.h" #include "php_unicode.h" #include "TSRM.h" diff --git a/main/SAPI.c b/main/SAPI.c index b77e060eda84..08c10b90598d 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -33,8 +33,6 @@ #include "rfc1867.h" -#include "php_content_types.h" - #ifdef ZTS SAPI_API int sapi_globals_id; SAPI_API size_t sapi_globals_offset; diff --git a/main/SAPI.h b/main/SAPI.h index 64ee19b76a91..08088fcc1bc8 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -307,6 +307,7 @@ END_EXTERN_C() #define DEFAULT_POST_CONTENT_TYPE "application/x-www-form-urlencoded" BEGIN_EXTERN_C() +SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data); SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data); SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter); diff --git a/main/main.c b/main/main.c index a12af698dfd1..6a3c5d332b4c 100644 --- a/main/main.c +++ b/main/main.c @@ -79,7 +79,6 @@ #include "zend_system_id.h" #include "zend_smart_string.h" -#include "php_content_types.h" #include "php_ticks.h" #include "php_streams.h" #include "php_open_temporary_file.h" diff --git a/main/php_content_types.c b/main/php_content_types.c deleted file mode 100644 index 5df0148cb69b..000000000000 --- a/main/php_content_types.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright © The PHP Group and Contributors. | - +----------------------------------------------------------------------+ - | This source file is subject to the Modified BSD License that is | - | bundled with this package in the file LICENSE, and is available | - | through the World Wide Web at . | - | | - | SPDX-License-Identifier: BSD-3-Clause | - +----------------------------------------------------------------------+ -*/ - -#include "php.h" -#include "SAPI.h" -#include "rfc1867.h" - -#include "php_content_types.h" - diff --git a/main/php_content_types.h b/main/php_content_types.h deleted file mode 100644 index e05b5161d3b4..000000000000 --- a/main/php_content_types.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright © The PHP Group and Contributors. | - +----------------------------------------------------------------------+ - | This source file is subject to the Modified BSD License that is | - | bundled with this package in the file LICENSE, and is available | - | through the World Wide Web at . | - | | - | SPDX-License-Identifier: BSD-3-Clause | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHP_CONTENT_TYPES_H -#define PHP_CONTENT_TYPES_H - -SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); - -#endif /* PHP_CONTENT_TYPES_H */ diff --git a/main/php_variables.c b/main/php_variables.c index 2121bfd8b35b..e4262e59c006 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -20,7 +20,6 @@ #include "zend_smart_str.h" #include "php_variables.h" #include "php_globals.h" -#include "php_content_types.h" #include "SAPI.h" #include "zend_globals.h" #include "zend_exceptions.h" diff --git a/win32/build/config.w32 b/win32/build/config.w32 index 253dab653986..991eeb33b020 100644 --- a/win32/build/config.w32 +++ b/win32/build/config.w32 @@ -288,7 +288,7 @@ ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c fopen_wrappers.c \ php_ini_builder.c php_glob.c \ - php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \ + php_scandir.c php_ini.c SAPI.c rfc1867.c strlcpy.c \ strlcat.c reentrancy.c php_variables.c php_ticks.c network.c \ php_open_temporary_file.c output.c internal_functions.c \ php_syslog.c php_odbc_utils.c safe_bcmp.c");