Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions main/php_variables.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ typedef struct post_var_data {
size_t already_scanned;
} post_var_data_t;

static bool add_post_var(zval *arr, post_var_data_t *var, bool eof)
static bool add_post_var(zval *arr, post_var_data_t *var, bool eof, bool register_var)
{
char *start, *ksep, *vsep, *val;
size_t klen, vlen;
Expand All @@ -367,6 +367,11 @@ static bool add_post_var(zval *arr, post_var_data_t *var, bool eof)
}
}

if (!register_var) {
/* Over max_input_vars; the caller reports the error. */
return 1;
}

ksep = memchr(var->ptr, '=', vsep - var->ptr);
if (ksep) {
*ksep = '\0';
Expand Down Expand Up @@ -411,7 +416,7 @@ static inline int add_post_vars(zval *arr, post_var_data_t *vars, bool eof)

vars->ptr = ZSTR_VAL(vars->str.s);
vars->end = ZSTR_VAL(vars->str.s) + ZSTR_LEN(vars->str.s);
while (add_post_var(arr, vars, eof)) {
while (add_post_var(arr, vars, eof, vars->cnt < max_vars)) {
if (++vars->cnt > max_vars) {
php_error_docref(NULL, E_WARNING,
"Input variables exceeded %" PRIu64 ". "
Expand Down
24 changes: 24 additions & 0 deletions tests/basic/max_input_vars_post_urlencoded.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
max_input_vars limit for urlencoded POST data
--INI--
max_input_vars=5
--POST--
a=1&b=2&c=3&d=4&e=5&f=6
--FILE--
<?php
var_dump($_POST);
?>
--EXPECT--
Warning: PHP Request Startup: Input variables exceeded 5. To increase the limit change max_input_vars in php.ini. in Unknown on line 0
array(5) {
["a"]=>
string(1) "1"
["b"]=>
string(1) "2"
["c"]=>
string(1) "3"
["d"]=>
string(1) "4"
["e"]=>
string(1) "5"
}
Loading