diff options
| author | jvoisin | 2017-10-24 00:16:30 +0200 |
|---|---|---|
| committer | jvoisin | 2017-10-24 00:16:30 +0200 |
| commit | 92a4b93c4d420fefe590bd88521ec76d8bebd3fe (patch) | |
| tree | c817f0cff179136fb4321822198481d05dde2c6c | |
| parent | ca51803abbe0b5605f936f5676d9c1a528713033 (diff) | |
Remove the `enable` member from the disable function structure
Also add some more tests
| -rw-r--r-- | src/sp_config.h | 1 | ||||
| -rw-r--r-- | src/sp_config_keywords.c | 10 | ||||
| -rw-r--r-- | src/sp_disabled_functions.c | 23 | ||||
| -rw-r--r-- | src/tests/config/config_disabled_functions_param_r.ini | 1 | ||||
| -rw-r--r-- | src/tests/config/disabled_functions_pos.ini | 1 | ||||
| -rw-r--r-- | src/tests/config/disabled_functions_ret.ini | 1 | ||||
| -rw-r--r-- | src/tests/disabled_functions_param_pos.phpt | 3 |
7 files changed, 21 insertions, 19 deletions
diff --git a/src/sp_config.h b/src/sp_config.h index c6de8ba..eda7517 100644 --- a/src/sp_config.h +++ b/src/sp_config.h | |||
| @@ -72,7 +72,6 @@ typedef struct { | |||
| 72 | 72 | ||
| 73 | char *hash; | 73 | char *hash; |
| 74 | int simulation; | 74 | int simulation; |
| 75 | bool enable; | ||
| 76 | 75 | ||
| 77 | char *param; | 76 | char *param; |
| 78 | pcre *r_param; | 77 | pcre *r_param; |
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 168ee1c..604c2a1 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c | |||
| @@ -182,12 +182,6 @@ int parse_disabled_functions(char *line) { | |||
| 182 | return ret; | 182 | return ret; |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | if (true == disable){ | ||
| 186 | df->enable = false; | ||
| 187 | } else { | ||
| 188 | df->enable = true; | ||
| 189 | } | ||
| 190 | |||
| 191 | if (df->value && df->value_r) { | 185 | if (df->value && df->value_r) { |
| 192 | sp_log_err("config", | 186 | sp_log_err("config", |
| 193 | "Invalid configuration line: 'sp.disabled_functions%s':" | 187 | "Invalid configuration line: 'sp.disabled_functions%s':" |
| @@ -296,6 +290,10 @@ int parse_disabled_functions(char *line) { | |||
| 296 | break; | 290 | break; |
| 297 | } | 291 | } |
| 298 | 292 | ||
| 293 | if (true == disable) { | ||
| 294 | return ret; | ||
| 295 | } | ||
| 296 | |||
| 299 | if (df->ret || df->r_ret || df->ret_type) { | 297 | if (df->ret || df->r_ret || df->ret_type) { |
| 300 | sp_list_insert( | 298 | sp_list_insert( |
| 301 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions, | 299 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions, |
diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c index f089c25..f0b785c 100644 --- a/src/sp_disabled_functions.c +++ b/src/sp_disabled_functions.c | |||
| @@ -124,10 +124,6 @@ bool should_disable(zend_execute_data* execute_data) { | |||
| 124 | const char* arg_name = NULL; | 124 | const char* arg_name = NULL; |
| 125 | const char* arg_value_str = NULL; | 125 | const char* arg_value_str = NULL; |
| 126 | 126 | ||
| 127 | if (false == config_node->enable) { | ||
| 128 | goto next; | ||
| 129 | } | ||
| 130 | |||
| 131 | /* The order matters, since when we have `config_node->functions_list`, | 127 | /* The order matters, since when we have `config_node->functions_list`, |
| 132 | we also do have `config_node->function` */ | 128 | we also do have `config_node->function` */ |
| 133 | if (config_node->functions_list) { | 129 | if (config_node->functions_list) { |
| @@ -189,9 +185,18 @@ bool should_disable(zend_execute_data* execute_data) { | |||
| 189 | bool arg_matched = false; | 185 | bool arg_matched = false; |
| 190 | int i = 0; | 186 | int i = 0; |
| 191 | 187 | ||
| 192 | if ((config_node->pos != -1) && (config_node->pos <= nb_param)) { | 188 | if (config_node->pos != -1) { |
| 193 | i = config_node->pos; | 189 | if (config_node->pos <= nb_param) { |
| 194 | nb_param = (config_node->pos) + 1; | 190 | sp_log_err("config", "It seems that you wrote a rule filtering on the " |
| 191 | "%d%s argument of the function '%s', but it takes only %d arguments. " | ||
| 192 | "Matching on _all_ arguments instead.", | ||
| 193 | config_node->pos, | ||
| 194 | (config_node->pos == 1)?"st":(config_node->pos)?"nd":"th", | ||
| 195 | complete_path_function, nb_param); | ||
| 196 | } else { | ||
| 197 | i = config_node->pos; | ||
| 198 | nb_param = (config_node->pos) + 1; | ||
| 199 | } | ||
| 195 | } | 200 | } |
| 196 | 201 | ||
| 197 | for (; i < nb_param; i++) { | 202 | for (; i < nb_param; i++) { |
| @@ -301,10 +306,6 @@ static bool should_drop_on_ret(zval* return_value, | |||
| 301 | sp_disabled_function const* const config_node = | 306 | sp_disabled_function const* const config_node = |
| 302 | (sp_disabled_function*)(config->data); | 307 | (sp_disabled_function*)(config->data); |
| 303 | 308 | ||
| 304 | if (false == config_node->enable) { | ||
| 305 | goto next; | ||
| 306 | } | ||
| 307 | |||
| 308 | if (config_node->function) { | 309 | if (config_node->function) { |
| 309 | if (0 != strcmp(config_node->function, complete_path_function)) { | 310 | if (0 != strcmp(config_node->function, complete_path_function)) { |
| 310 | goto next; | 311 | goto next; |
diff --git a/src/tests/config/config_disabled_functions_param_r.ini b/src/tests/config/config_disabled_functions_param_r.ini index 8e9ac63..09a59fe 100644 --- a/src/tests/config/config_disabled_functions_param_r.ini +++ b/src/tests/config/config_disabled_functions_param_r.ini | |||
| @@ -1 +1,2 @@ | |||
| 1 | sp.disable_function.function("system").param_r("^not_command$").value("id").drop(); | ||
| 1 | sp.disable_function.function("system").param_r("^command$").value("id").drop(); | 2 | sp.disable_function.function("system").param_r("^command$").value("id").drop(); |
diff --git a/src/tests/config/disabled_functions_pos.ini b/src/tests/config/disabled_functions_pos.ini index f96cf3d..e7d12a9 100644 --- a/src/tests/config/disabled_functions_pos.ini +++ b/src/tests/config/disabled_functions_pos.ini | |||
| @@ -1 +1,2 @@ | |||
| 1 | sp.disable_function.function("system").pos("1337").value("id").drop(); | ||
| 1 | sp.disable_function.function("system").pos("0").value("id").drop(); | 2 | sp.disable_function.function("system").pos("0").value("id").drop(); |
diff --git a/src/tests/config/disabled_functions_ret.ini b/src/tests/config/disabled_functions_ret.ini index 4afcd34..288177a 100644 --- a/src/tests/config/disabled_functions_ret.ini +++ b/src/tests/config/disabled_functions_ret.ini | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | sp.disable_function.function("testFunction").ret("0").drop().disable(); | 1 | sp.disable_function.function("testFunction").ret("0").drop().disable(); |
| 2 | sp.disable_function.function("strpos").ret("0").drop().filename_r(".*\\.not_matching"); | ||
| 2 | sp.disable_function.function("strpos").ret("0").drop().filename_r(".*\\.php"); | 3 | sp.disable_function.function("strpos").ret("0").drop().filename_r(".*\\.php"); |
| 3 | sp.disable_function.function_r("str[ia]pos").ret_r("^[^a-z]+$").drop(); | 4 | sp.disable_function.function_r("str[ia]pos").ret_r("^[^a-z]+$").drop(); |
| 4 | sp.disable_function.function_r("stripos").ret_r("^[^a-z]+").drop(); | 5 | sp.disable_function.function_r("stripos").ret_r("^[^a-z]+").drop(); |
diff --git a/src/tests/disabled_functions_param_pos.phpt b/src/tests/disabled_functions_param_pos.phpt index de578b2..a1f8895 100644 --- a/src/tests/disabled_functions_param_pos.phpt +++ b/src/tests/disabled_functions_param_pos.phpt | |||
| @@ -9,4 +9,5 @@ sp.configuration_file={PWD}/config/disabled_functions_pos.ini | |||
| 9 | system("id"); | 9 | system("id"); |
| 10 | ?> | 10 | ?> |
| 11 | --EXPECTF-- | 11 | --EXPECTF-- |
| 12 | [snuffleupagus][0.0.0.0][disabled_function][drop] The call to the function 'system' in %a/disabled_functions_param_pos.php:%d has been disabled, because its argument 'command' content (id) matched a rule. | 12 | [snuffleupagus][0.0.0.0][config][error] It seems that you wrote a rule filtering on the 0th argument of the function 'system', but it takes only 2 arguments. Matching on _all_ arguments instead. |
| 13 | [snuffleupagus][0.0.0.0][disabled_function][drop] The call to the function 'system' in %a/disabled_functions_param_pos.php:2 has been disabled, because its argument 'command' content (id) matched a rule. | ||
