diff options
| author | jvoisin | 2017-12-28 11:27:06 +0100 |
|---|---|---|
| committer | jvoisin | 2017-12-28 11:27:06 +0100 |
| commit | 89432f57aa9769d2efd5b8934241d10b005afd1a (patch) | |
| tree | 017061381147cb34c47ee9325cc3ab26a30c24db /src | |
| parent | ad4c76191bded05c419524a6fe03a14157b767ff (diff) | |
Implement hooking on user-defined functions return values
This should close #99, thanks to @blotus for the implementation idea!
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp_disabled_functions.c | 2 | ||||
| -rw-r--r-- | src/sp_disabled_functions.h | 1 | ||||
| -rw-r--r-- | src/sp_execute.c | 4 | ||||
| -rw-r--r-- | src/tests/disabled_functions_ret_type_object.phpt | 3 |
4 files changed, 7 insertions, 3 deletions
diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c index 18545c0..9736d2b 100644 --- a/src/sp_disabled_functions.c +++ b/src/sp_disabled_functions.c | |||
| @@ -339,7 +339,7 @@ allow: | |||
| 339 | return false; | 339 | return false; |
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | static bool should_drop_on_ret(zval* return_value, | 342 | bool should_drop_on_ret(zval* return_value, |
| 343 | const zend_execute_data* const execute_data) { | 343 | const zend_execute_data* const execute_data) { |
| 344 | const sp_list_node* config = | 344 | const sp_list_node* config = |
| 345 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions; | 345 | SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions; |
diff --git a/src/sp_disabled_functions.h b/src/sp_disabled_functions.h index e9180c9..e43afe8 100644 --- a/src/sp_disabled_functions.h +++ b/src/sp_disabled_functions.h | |||
| @@ -3,5 +3,6 @@ | |||
| 3 | 3 | ||
| 4 | int hook_disabled_functions(); | 4 | int hook_disabled_functions(); |
| 5 | bool should_disable(zend_execute_data*, const char *, const char *, const char *); | 5 | bool should_disable(zend_execute_data*, const char *, const char *, const char *); |
| 6 | bool should_drop_on_ret(zval*, const zend_execute_data* const); | ||
| 6 | 7 | ||
| 7 | #endif /* __SP_DISABLE_FUNCTIONS_H */ | 8 | #endif /* __SP_DISABLE_FUNCTIONS_H */ |
diff --git a/src/sp_execute.c b/src/sp_execute.c index 2a62fd8..a541bfb 100644 --- a/src/sp_execute.c +++ b/src/sp_execute.c | |||
| @@ -78,6 +78,10 @@ static void sp_execute_ex(zend_execute_data *execute_data) { | |||
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | orig_execute_ex(execute_data); | 80 | orig_execute_ex(execute_data); |
| 81 | |||
| 82 | if (true == should_drop_on_ret(execute_data->return_value, execute_data)) { | ||
| 83 | sp_terminate(); | ||
| 84 | } | ||
| 81 | } | 85 | } |
| 82 | 86 | ||
| 83 | static int sp_stream_open(const char *filename, zend_file_handle *handle) { | 87 | static int sp_stream_open(const char *filename, zend_file_handle *handle) { |
diff --git a/src/tests/disabled_functions_ret_type_object.phpt b/src/tests/disabled_functions_ret_type_object.phpt index 66f298c..eb07cc3 100644 --- a/src/tests/disabled_functions_ret_type_object.phpt +++ b/src/tests/disabled_functions_ret_type_object.phpt | |||
| @@ -4,8 +4,6 @@ Disable functions check on `ret` by type matching (object). | |||
| 4 | <?php if (!extension_loaded("snuffleupagus")) die "skip"; ?> | 4 | <?php if (!extension_loaded("snuffleupagus")) die "skip"; ?> |
| 5 | --INI-- | 5 | --INI-- |
| 6 | sp.configuration_file={PWD}/config/disabled_functions_ret_type_object.ini | 6 | sp.configuration_file={PWD}/config/disabled_functions_ret_type_object.ini |
| 7 | --XFAIL-- | ||
| 8 | We're not implementing hooking on retval of user functions yet | ||
| 9 | --FILE-- | 7 | --FILE-- |
| 10 | <?php | 8 | <?php |
| 11 | function a(){ | 9 | function a(){ |
| @@ -15,3 +13,4 @@ $var = a(); | |||
| 15 | echo "fail"; | 13 | echo "fail"; |
| 16 | ?> | 14 | ?> |
| 17 | --EXPECTF-- | 15 | --EXPECTF-- |
| 16 | [snuffleupagus][0.0.0.0][disabled_function][drop] The execution has been aborted in %a/tests/disabled_functions_ret_type_object.php:5, because the return value (OBJECT) of the function 'a' matched a rule. | ||
