diff -u -r php-5.2.17/main/main.c php-5.2.17-patched/main/main.c --- php-5.2.17/main/main.c 2010-06-20 04:47:24.000000000 +0800 +++ php-5.2.17-patched/main/main.c 2011-12-31 09:59:05.000000000 +0800 @@ -457,6 +457,7 @@ STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("allow_url_include", "0", PHP_INI_SYSTEM, OnUpdateBool, allow_url_include, php_core_globals, core_globals) + STD_PHP_INI_ENTRY("max_input_vars", "1000", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLongGEZero, max_input_vars, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("always_populate_raw_post_data", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, always_populate_raw_post_data, php_core_globals, core_globals) STD_PHP_INI_ENTRY("realpath_cache_size", "16K", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_size_limit, virtual_cwd_globals, cwd_globals) diff -u -r php-5.2.17/main/php_globals.h php-5.2.17-patched/main/php_globals.h --- php-5.2.17/main/php_globals.h 2010-01-03 17:23:27.000000000 +0800 +++ php-5.2.17-patched/main/php_globals.h 2011-12-31 09:59:05.000000000 +0800 @@ -160,6 +160,7 @@ zend_bool com_initialized; #endif long max_input_nesting_level; + long max_input_vars; zend_bool in_user_include; zend_bool in_error_log; }; diff -u -r php-5.2.17/main/php_variables.c php-5.2.17-patched/main/php_variables.c --- php-5.2.17/main/php_variables.c 2010-01-03 17:23:27.000000000 +0800 +++ php-5.2.17-patched/main/php_variables.c 2011-12-31 09:59:05.000000000 +0800 @@ -187,6 +187,9 @@ } if (zend_symtable_find(symtable1, escaped_index, index_len + 1, (void **) &gpc_element_p) == FAILURE || Z_TYPE_PP(gpc_element_p) != IS_ARRAY) { + if (zend_hash_num_elements(symtable1) >= PG(max_input_vars)) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Input variables exceeded %ld. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars)); + } MAKE_STD_ZVAL(gpc_element); array_init(gpc_element); zend_symtable_update(symtable1, escaped_index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p); @@ -232,6 +235,9 @@ zend_symtable_exists(symtable1, escaped_index, index_len + 1)) { zval_ptr_dtor(&gpc_element); } else { + if (zend_hash_num_elements(symtable1) >= PG(max_input_vars)) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Input variables exceeded %ld. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars)); + } zend_symtable_update(symtable1, escaped_index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p); } if (escaped_index != index) {