summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sp_disabled_functions.c40
-rw-r--r--src/sp_disabled_functions.h6
-rw-r--r--src/sp_execute.c14
-rw-r--r--src/tests/disabled_functions_ret3.phpt2
4 files changed, 27 insertions, 35 deletions
diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c
index f6e06e4..2e459a9 100644
--- a/src/sp_disabled_functions.c
+++ b/src/sp_disabled_functions.c
@@ -250,11 +250,10 @@ static bool check_is_builtin_name(
250} 250}
251 251
252bool should_disable_ht(zend_execute_data* execute_data, 252bool should_disable_ht(zend_execute_data* execute_data,
253 const char* builtin_name, 253 const char* function_name,
254 const zend_string* builtin_param, 254 const zend_string* builtin_param,
255 const char* builtin_param_name, 255 const char* builtin_param_name,
256 const sp_list_node* config, const HashTable* ht) { 256 const sp_list_node* config, const HashTable* ht) {
257 char* complete_function_path = NULL;
258 const sp_list_node* ht_entry = NULL; 257 const sp_list_node* ht_entry = NULL;
259 bool ret = false; 258 bool ret = false;
260 zend_string* current_filename; 259 zend_string* current_filename;
@@ -263,35 +262,24 @@ bool should_disable_ht(zend_execute_data* execute_data,
263 return false; 262 return false;
264 } 263 }
265 264
266 if (builtin_name) { 265 if (UNEXPECTED(builtin_param && !strcmp(function_name, "eval"))) {
267 complete_function_path = estrdup(builtin_name);
268 } else {
269 complete_function_path = get_complete_function_path(execute_data);
270 if (!complete_function_path) {
271 return false;
272 }
273 }
274
275 if (UNEXPECTED(builtin_param && !strcmp(complete_function_path, "eval"))) {
276 current_filename = get_eval_filename(zend_get_executed_filename()); 266 current_filename = get_eval_filename(zend_get_executed_filename());
277 } else { 267 } else {
278 const char* tmp = zend_get_executed_filename(); 268 const char* tmp = zend_get_executed_filename();
279 current_filename = zend_string_init(tmp, strlen(tmp), 0); 269 current_filename = zend_string_init(tmp, strlen(tmp), 0);
280 } 270 }
281 271
282 ht_entry = zend_hash_str_find_ptr(ht, complete_function_path, 272 ht_entry = zend_hash_str_find_ptr(ht, function_name, strlen(function_name));
283 strlen(complete_function_path));
284 273
285 if (ht_entry && 274 if (ht_entry &&
286 should_disable(execute_data, complete_function_path, builtin_param, 275 should_disable(execute_data, function_name, builtin_param,
287 builtin_param_name, ht_entry, current_filename)) { 276 builtin_param_name, ht_entry, current_filename)) {
288 ret = true; 277 ret = true;
289 } else if (config && config->data) { 278 } else if (config && config->data) {
290 ret = should_disable(execute_data, complete_function_path, builtin_param, 279 ret = should_disable(execute_data, function_name, builtin_param,
291 builtin_param_name, config, current_filename); 280 builtin_param_name, config, current_filename);
292 } 281 }
293 282
294 efree(complete_function_path);
295 efree(current_filename); 283 efree(current_filename);
296 return ret; 284 return ret;
297} 285}
@@ -423,28 +411,24 @@ allow:
423 return false; 411 return false;
424} 412}
425 413
426bool should_drop_on_ret_ht(zval* return_value, 414bool should_drop_on_ret_ht(zval* return_value, const char* function_name,
427 const zend_execute_data* const execute_data,
428 const sp_list_node* config, const HashTable* ht) { 415 const sp_list_node* config, const HashTable* ht) {
429 char* complete_function_path = get_complete_function_path(execute_data);
430 const sp_list_node* ht_entry = NULL; 416 const sp_list_node* ht_entry = NULL;
431 bool ret = false; 417 bool ret = false;
432 418
433 if (!complete_function_path) { 419 if (!function_name) {
434 return ret; 420 return ret;
435 } 421 }
436 422
437 ht_entry = zend_hash_str_find_ptr(ht, complete_function_path, 423 ht_entry = zend_hash_str_find_ptr(ht, function_name, strlen(function_name));
438 strlen(complete_function_path));
439 424
440 if (ht_entry && 425 if (ht_entry &&
441 should_drop_on_ret(return_value, ht_entry, complete_function_path)) { 426 should_drop_on_ret(return_value, ht_entry, function_name)) {
442 ret = true; 427 ret = true;
443 } else if (config && config->data) { 428 } else if (config && config->data) {
444 ret = should_drop_on_ret(return_value, config, complete_function_path); 429 ret = should_drop_on_ret(return_value, config, function_name);
445 } 430 }
446 431
447 efree(complete_function_path);
448 return ret; 432 return ret;
449} 433}
450 434
@@ -522,7 +506,7 @@ ZEND_FUNCTION(check_disabled_function) {
522 const char* current_function_name = get_active_function_name(TSRMLS_C); 506 const char* current_function_name = get_active_function_name(TSRMLS_C);
523 507
524 if (true == should_disable_ht( 508 if (true == should_disable_ht(
525 execute_data, NULL, NULL, NULL, 509 execute_data, current_function_name, NULL, NULL,
526 SNUFFLEUPAGUS_G(config) 510 SNUFFLEUPAGUS_G(config)
527 .config_disabled_functions_reg->disabled_functions, 511 .config_disabled_functions_reg->disabled_functions,
528 SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked)) { 512 SNUFFLEUPAGUS_G(config).config_disabled_functions_hooked)) {
@@ -535,7 +519,7 @@ ZEND_FUNCTION(check_disabled_function) {
535 orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); 519 orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
536 if (true == 520 if (true ==
537 should_drop_on_ret_ht( 521 should_drop_on_ret_ht(
538 return_value, execute_data, 522 return_value, current_function_name,
539 SNUFFLEUPAGUS_G(config) 523 SNUFFLEUPAGUS_G(config)
540 .config_disabled_functions_reg_ret->disabled_functions, 524 .config_disabled_functions_reg_ret->disabled_functions,
541 SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked)) { 525 SNUFFLEUPAGUS_G(config).config_disabled_functions_ret_hooked)) {
diff --git a/src/sp_disabled_functions.h b/src/sp_disabled_functions.h
index 83b1551..4e9f7ad 100644
--- a/src/sp_disabled_functions.h
+++ b/src/sp_disabled_functions.h
@@ -8,8 +8,10 @@ int hook_echo(const char*, size_t);
8bool should_disable(zend_execute_data *, const char *, const zend_string *, 8bool should_disable(zend_execute_data *, const char *, const zend_string *,
9 const char *, const sp_list_node *, const zend_string *); 9 const char *, const sp_list_node *, const zend_string *);
10bool should_disable_ht(zend_execute_data *, const char *, const zend_string *, 10bool should_disable_ht(zend_execute_data *, const char *, const zend_string *,
11 const char *, const sp_list_node *, const HashTable *); 11 const char *, const sp_list_node *, const HashTable *);
12bool should_drop_on_ret_ht(zval *, const zend_execute_data *const, const sp_list_node* config, const HashTable *); 12bool should_drop_on_ret_ht(zval *, const char *, const sp_list_node* config,
13 const HashTable *);
13bool should_drop_on_ret(zval *, const sp_list_node* config, const char *); 14bool should_drop_on_ret(zval *, const sp_list_node* config, const char *);
15char* get_complete_function_path(zend_execute_data const* const);
14 16
15#endif /* __SP_DISABLE_FUNCTIONS_H */ 17#endif /* __SP_DISABLE_FUNCTIONS_H */
diff --git a/src/sp_execute.c b/src/sp_execute.c
index 6e38c75..96d9d85 100644
--- a/src/sp_execute.c
+++ b/src/sp_execute.c
@@ -150,13 +150,20 @@ static void sp_execute_ex(zend_execute_data *execute_data) {
150 } 150 }
151 151
152 if (SNUFFLEUPAGUS_G(config).hook_execute) { 152 if (SNUFFLEUPAGUS_G(config).hook_execute) {
153 char* function_name = get_complete_function_path(execute_data);
154
155 if (!function_name) {
156 orig_execute_ex(execute_data);
157 return;
158 }
159
153 if (!execute_data->prev_execute_data || 160 if (!execute_data->prev_execute_data ||
154 !execute_data->prev_execute_data->func || 161 !execute_data->prev_execute_data->func ||
155 !ZEND_USER_CODE(execute_data->prev_execute_data->func->type) || 162 !ZEND_USER_CODE(execute_data->prev_execute_data->func->type) ||
156 !execute_data->prev_execute_data->opline) { 163 !execute_data->prev_execute_data->opline) {
157 if (UNEXPECTED(true == 164 if (UNEXPECTED(true ==
158 should_disable_ht( 165 should_disable_ht(
159 execute_data, NULL, NULL, NULL, 166 execute_data, function_name, NULL, NULL,
160 SNUFFLEUPAGUS_G(config) 167 SNUFFLEUPAGUS_G(config)
161 .config_disabled_functions_reg->disabled_functions, 168 .config_disabled_functions_reg->disabled_functions,
162 SNUFFLEUPAGUS_G(config).config_disabled_functions))) { 169 SNUFFLEUPAGUS_G(config).config_disabled_functions))) {
@@ -170,7 +177,7 @@ static void sp_execute_ex(zend_execute_data *execute_data) {
170 ZEND_DO_FCALL_BY_NAME)) { 177 ZEND_DO_FCALL_BY_NAME)) {
171 if (UNEXPECTED(true == 178 if (UNEXPECTED(true ==
172 should_disable_ht( 179 should_disable_ht(
173 execute_data, NULL, NULL, NULL, 180 execute_data, function_name, NULL, NULL,
174 SNUFFLEUPAGUS_G(config) 181 SNUFFLEUPAGUS_G(config)
175 .config_disabled_functions_reg->disabled_functions, 182 .config_disabled_functions_reg->disabled_functions,
176 SNUFFLEUPAGUS_G(config).config_disabled_functions))) { 183 SNUFFLEUPAGUS_G(config).config_disabled_functions))) {
@@ -183,12 +190,13 @@ static void sp_execute_ex(zend_execute_data *execute_data) {
183 if (UNEXPECTED( 190 if (UNEXPECTED(
184 true == 191 true ==
185 should_drop_on_ret_ht( 192 should_drop_on_ret_ht(
186 EX(return_value), execute_data, 193 EX(return_value), function_name,
187 SNUFFLEUPAGUS_G(config) 194 SNUFFLEUPAGUS_G(config)
188 .config_disabled_functions_reg_ret->disabled_functions, 195 .config_disabled_functions_reg_ret->disabled_functions,
189 SNUFFLEUPAGUS_G(config).config_disabled_functions_ret))) { 196 SNUFFLEUPAGUS_G(config).config_disabled_functions_ret))) {
190 sp_terminate(); 197 sp_terminate();
191 } 198 }
199 efree(function_name);
192 } else { 200 } else {
193 orig_execute_ex(execute_data); 201 orig_execute_ex(execute_data);
194 } 202 }
diff --git a/src/tests/disabled_functions_ret3.phpt b/src/tests/disabled_functions_ret3.phpt
index 87af0d3..87a44ef 100644
--- a/src/tests/disabled_functions_ret3.phpt
+++ b/src/tests/disabled_functions_ret3.phpt
@@ -20,5 +20,3 @@ echo("We're at the end of the execution.\n");
20--EXPECTF-- 20--EXPECTF--
21We're in function `a`. 21We're in function `a`.
22[snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on return of the function 'Bob::a' in %a/disabled_functions_ret3.php:9, because the function returned '2', which matched a rule. 22[snuffleupagus][0.0.0.0][disabled_function][drop] Aborted execution on return of the function 'Bob::a' in %a/disabled_functions_ret3.php:9, because the function returned '2', which matched a rule.
23--XFAIL--
24Match on ret is broken for non-native functions :/