From b1bf270b41f94ce2df668be611e5b646397a7a52 Mon Sep 17 00:00:00 2001 From: xXx-caillou-xXx Date: Fri, 13 Jul 2018 14:47:49 +0200 Subject: Fix hooking on `print` --- src/sp_config_keywords.c | 5 +++++ src/sp_disabled_functions.c | 10 ++-------- src/tests/config/disabled_function_print.ini | 1 + src/tests/disabled_function_print.phpt | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 src/tests/config/disabled_function_print.ini create mode 100644 src/tests/disabled_function_print.phpt diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 81f43f7..8e1c2dc 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c @@ -472,6 +472,11 @@ int parse_disabled_functions(char *line) { return ret; } + if (df->function && zend_string_equals_literal(df->function, "print")) { + zend_string_release(df->function); + df->function = zend_string_init("echo", strlen("echo"), 1); + } + if (df->function && !df->functions_list) { if (df->ret || df->r_ret || df->ret_type) { add_df_to_hashtable(SNUFFLEUPAGUS_G(config).config_disabled_functions_ret, diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c index f266951..f6e06e4 100644 --- a/src/sp_disabled_functions.c +++ b/src/sp_disabled_functions.c @@ -573,14 +573,8 @@ static int hook_functions(HashTable* to_hook_ht, HashTable* hooked_ht) { if (!HOOK_FUNCTION(ZSTR_VAL(key), disabled_functions_hook, PHP_FN(check_disabled_function)) || check_is_builtin_name(((sp_list_node*)Z_PTR_P(value))->data)) { - if (zend_string_equals_literal(key, "echo") || - zend_string_equals_literal(key, "print")) { - zend_hash_str_add_new(hooked_ht, "echo", strlen("echo"), value); - zend_hash_del(to_hook_ht, key); - } else { - zend_symtable_add_new(hooked_ht, key, value); - zend_hash_del(to_hook_ht, key); - } + zend_symtable_add_new(hooked_ht, key, value); + zend_hash_del(to_hook_ht, key); } } ZEND_HASH_FOREACH_END(); diff --git a/src/tests/config/disabled_function_print.ini b/src/tests/config/disabled_function_print.ini new file mode 100644 index 0000000..22d957f --- /dev/null +++ b/src/tests/config/disabled_function_print.ini @@ -0,0 +1 @@ +sp.disable_function.function("print").value("oops").drop(); diff --git a/src/tests/disabled_function_print.phpt b/src/tests/disabled_function_print.phpt new file mode 100644 index 0000000..fc05360 --- /dev/null +++ b/src/tests/disabled_function_print.phpt @@ -0,0 +1,18 @@ +--TEST-- +Echo hooking +--SKIPIF-- + +--INI-- +sp.configuration_file={PWD}/config/disabled_function_print.ini +--FILE-- + +--CLEAN-- +--EXPECTF-- +qwerty[snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on call of the function 'echo' in %a/tests/disabled_function_print.php:3. -- cgit v1.3