diff options
| author | xXx-caillou-xXx | 2021-01-03 00:11:09 +0100 |
|---|---|---|
| committer | jvoisin | 2021-01-04 20:59:46 +0100 |
| commit | f4e3a800aa5a243464911fc2e9fa81a7848c57f7 (patch) | |
| tree | a8e56382c7236cb1371704404a06039a26a7bc8d /src | |
| parent | 48f927e9694fcfd76d9fe97542359c8b0bd0a46d (diff) | |
Add a check on parameters names
Snuffleupagus will now warn when a particular function
doesn't have the expected parameters configuration-wise.
Diffstat (limited to 'src')
5 files changed, 31 insertions, 6 deletions
diff --git a/src/sp_pcre_compat.c b/src/sp_pcre_compat.c index 283eeb7..509a8ea 100644 --- a/src/sp_pcre_compat.c +++ b/src/sp_pcre_compat.c | |||
| @@ -14,8 +14,7 @@ sp_pcre* sp_pcre_compile(const char* const pattern) { | |||
| 14 | #else | 14 | #else |
| 15 | const char* pcre_error = NULL; | 15 | const char* pcre_error = NULL; |
| 16 | int erroroffset; | 16 | int erroroffset; |
| 17 | ret = | 17 | ret = pcre_compile(pattern, PCRE_CASELESS, &pcre_error, &erroroffset, NULL); |
| 18 | pcre_compile(pattern, PCRE_CASELESS, &pcre_error, &erroroffset, NULL); | ||
| 19 | #endif | 18 | #endif |
| 20 | 19 | ||
| 21 | if (NULL == ret) { | 20 | if (NULL == ret) { |
| @@ -38,8 +37,7 @@ bool ZEND_HOT sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, | |||
| 38 | ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); | 37 | ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); |
| 39 | #else | 38 | #else |
| 40 | int vec[30]; | 39 | int vec[30]; |
| 41 | ret = pcre_exec(regexp, NULL, str, len, 0, 0, vec, | 40 | ret = pcre_exec(regexp, NULL, str, len, 0, 0, vec, sizeof(vec) / sizeof(int)); |
| 42 | sizeof(vec) / sizeof(int)); | ||
| 43 | #endif | 41 | #endif |
| 44 | 42 | ||
| 45 | if (ret < 0) { | 43 | if (ret < 0) { |
diff --git a/src/sp_var_value.c b/src/sp_var_value.c index 986ea2d..126ba0e 100644 --- a/src/sp_var_value.c +++ b/src/sp_var_value.c | |||
| @@ -68,7 +68,18 @@ static zval *get_var_value(zend_execute_data *ed, const char *var_name, | |||
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | if (is_param) { | 70 | if (is_param) { |
| 71 | return get_param_var(ed, var_name); | 71 | zval *zvalue = get_param_var(ed, var_name); |
| 72 | if (!zvalue) { | ||
| 73 | const char *complete_function_path = get_complete_function_path(ed); | ||
| 74 | sp_log_warn("config", | ||
| 75 | "It seems that you are filtering on a parameter " | ||
| 76 | "'%s' of the function '%s', but the parameter does " | ||
| 77 | "not exists.", | ||
| 78 | var_name, complete_function_path); | ||
| 79 | efree(complete_function_path); | ||
| 80 | return NULL; | ||
| 81 | } | ||
| 82 | return zvalue; | ||
| 72 | } else { | 83 | } else { |
| 73 | return get_local_var(ed, var_name); | 84 | return get_local_var(ed, var_name); |
| 74 | } | 85 | } |
diff --git a/src/tests/broken_configuration/broken_conf_config_invalid_param.phpt b/src/tests/broken_configuration/broken_conf_config_invalid_param.phpt new file mode 100644 index 0000000..ac85dea --- /dev/null +++ b/src/tests/broken_configuration/broken_conf_config_invalid_param.phpt | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | --TEST-- | ||
| 2 | Broken configuration with invalid parameter warning | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) print "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/broken_conf_config_invalid_param.ini | ||
| 7 | --FILE-- | ||
| 8 | <?php | ||
| 9 | function foo($blah, $x = null, $y = null) { | ||
| 10 | echo "ok"; | ||
| 11 | } | ||
| 12 | |||
| 13 | foo("qwe"); | ||
| 14 | --EXPECTF-- | ||
| 15 | Warning: [snuffleupagus][0.0.0.0][config][log] It seems that you are filtering on a parameter 'qwe' of the function 'foo', but the parameter does not exists. in %s/tests/broken_configuration/broken_conf_config_invalid_param.php on line %d | ||
| 16 | ok | ||
diff --git a/src/tests/broken_configuration/config/broken_conf_config_invalid_param.ini b/src/tests/broken_configuration/config/broken_conf_config_invalid_param.ini new file mode 100644 index 0000000..22894c8 --- /dev/null +++ b/src/tests/broken_configuration/config/broken_conf_config_invalid_param.ini | |||
| @@ -0,0 +1 @@ | |||
| sp.disable_function.function("foo").param("qwe").value("abc").drop() | |||
diff --git a/src/tests/disable_function/config/config_disabled_functions_param_array.ini b/src/tests/disable_function/config/config_disabled_functions_param_array.ini index f676d76..2bfa648 100644 --- a/src/tests/disable_function/config/config_disabled_functions_param_array.ini +++ b/src/tests/disable_function/config/config_disabled_functions_param_array.ini | |||
| @@ -4,4 +4,3 @@ sp.disable_function.function("foo").param("arr[test]").alias("3").drop(); | |||
| 4 | sp.disable_function.function("foo").param("arr[test2][foo]").value("aaa").alias("4").drop(); | 4 | sp.disable_function.function("foo").param("arr[test2][foo]").value("aaa").alias("4").drop(); |
| 5 | sp.disable_function.function("foo").param("arr[test2][bar]").key("lol").alias("5").drop(); | 5 | sp.disable_function.function("foo").param("arr[test2][bar]").key("lol").alias("5").drop(); |
| 6 | sp.disable_function.function("foo").param("arr[test2][bar]").key("123").alias("6").drop(); | 6 | sp.disable_function.function("foo").param("arr[test2][bar]").key("123").alias("6").drop(); |
| 7 | sp.disable_function.function("foo").param("qwe[a]").value("abcd").alias("7").drop(); | ||
