diff options
| author | jvoisin | 2017-10-09 11:54:31 +0200 |
|---|---|---|
| committer | GitHub | 2017-10-09 11:54:31 +0200 |
| commit | 1602780f3c85ca127c77d28ae93a4e2a4eeae180 (patch) | |
| tree | 1200952d6f20b0dbc94d6252dcdaba5be0bad353 /src/sp_config_keywords.c | |
| parent | 7234fdbb0cb0dd45ed1d6e7814c91e596126ee25 (diff) | |
Better hooking of language constructs (#26)
* Vastly improve the support of language construct hooking
Diffstat (limited to 'src/sp_config_keywords.c')
| -rw-r--r-- | src/sp_config_keywords.c | 67 |
1 files changed, 53 insertions, 14 deletions
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index d6107c3..8fba868 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c | |||
| @@ -2,6 +2,51 @@ | |||
| 2 | 2 | ||
| 3 | ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus) | 3 | ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus) |
| 4 | 4 | ||
| 5 | |||
| 6 | static int get_construct_type(sp_disabled_function const *const df) { | ||
| 7 | const struct { | ||
| 8 | unsigned int type; | ||
| 9 | char *keys[5]; | ||
| 10 | } mapping[] = { | ||
| 11 | { | ||
| 12 | .type = ZEND_INCLUDE_OR_EVAL, | ||
| 13 | .keys = {"include", "include_once", "require", "require_once", NULL} | ||
| 14 | },{ | ||
| 15 | .type = ZEND_ECHO, | ||
| 16 | .keys = {"echo", NULL} | ||
| 17 | },{ | ||
| 18 | .type = ZEND_NEW, | ||
| 19 | .keys = {"new", NULL} | ||
| 20 | },{ | ||
| 21 | .type = ZEND_EXIT, | ||
| 22 | .keys = {"exit", NULL} | ||
| 23 | },{ | ||
| 24 | .type = ZEND_STRLEN, | ||
| 25 | .keys = {"strlen", NULL} | ||
| 26 | },{ | ||
| 27 | .type = 0, | ||
| 28 | .keys = {NULL} | ||
| 29 | } | ||
| 30 | }; | ||
| 31 | |||
| 32 | // FIXME: This can be optimized | ||
| 33 | // FIXME the ->function and r_fonction tests are _wrong_ | ||
| 34 | for (size_t i=0; 0 != mapping[i].type; i++) { | ||
| 35 | for (size_t j=0; NULL != mapping[i].keys[j]; j++) { | ||
| 36 | if (df->function) { | ||
| 37 | if (0 == strcmp(df->function, mapping[i].keys[j])) { | ||
| 38 | return mapping[i].type; | ||
| 39 | } | ||
| 40 | } else if (df->r_function) { | ||
| 41 | if (true == is_regexp_matching(df->r_function, mapping[i].keys[j])) { | ||
| 42 | return mapping[i].type; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
| 47 | return -1; | ||
| 48 | } | ||
| 49 | |||
| 5 | static int parse_enable(char *line, bool * restrict retval, bool * restrict simulation) { | 50 | static int parse_enable(char *line, bool * restrict retval, bool * restrict simulation) { |
| 6 | bool enable = false, disable = false; | 51 | bool enable = false, disable = false; |
| 7 | sp_config_functions sp_config_funcs[] = { | 52 | sp_config_functions sp_config_funcs[] = { |
| @@ -207,22 +252,16 @@ int parse_disabled_functions(char *line) { | |||
| 207 | df->var_is_array = 1; | 252 | df->var_is_array = 1; |
| 208 | } | 253 | } |
| 209 | 254 | ||
| 210 | bool match = false; | 255 | switch (get_construct_type(df)) { |
| 211 | const char *key[4] = {"include", "include_once", "require", "require_once"}; | 256 | case ZEND_INCLUDE_OR_EVAL: |
| 212 | for (size_t i = 0; i < 4; i++) { | 257 | sp_list_insert(SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_include, df); |
| 213 | if (df->r_function && true == is_regexp_matching(df->r_function, key[i])) { | 258 | return ret; |
| 214 | match = true; | 259 | case ZEND_ECHO: |
| 215 | break; | 260 | default: |
| 216 | } else if (df->function && 0 == strcmp(df->function, key[i])) { | ||
| 217 | match = true; | ||
| 218 | break; | 261 | break; |
| 219 | } | ||
| 220 | } | 262 | } |
| 221 | if (true == match && df->regexp) { | 263 | |
| 222 | sp_list_insert( | 264 | if (df->ret || df->r_ret || df->ret_type) { |
| 223 | SNUFFLEUPAGUS_G(config).config_regexp_inclusion->regexp_inclusion, | ||
| 224 | df->regexp); | ||
| 225 | } else if (df->ret || df->r_ret || df->ret_type) { | ||
| 226 | sp_list_insert( | 265 | sp_list_insert( |
| 227 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions, | 266 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions, |
| 228 | df); | 267 | df); |
