summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Watkins <krakjoe@php.net>2017-01-04 13:35:01 +0000
committerJoe Watkins <krakjoe@php.net>2017-01-04 13:36:04 +0000
commit6c9164047e7b5c1879d7d43d36622aec8e83d7aa (patch)
tree3bc261ac9092ca1e37258edfb939a1b38d018d10
parentb15cc7913a1aa108b3e27c8c361202785bea4033 (diff)
parent63d116e5711e995f201ba6411bcb3929e5cbf041 (diff)
downloadphp-git-6c9164047e7b5c1879d7d43d36622aec8e83d7aa.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: get_defined_functions additional parameter to exclude disabled functions news entry for PR #1312
-rw-r--r--NEWS2
-rw-r--r--Zend/zend_builtin_functions.c16
-rw-r--r--tests/basic/bug31875.phpt23
3 files changed, 38 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 80e91c4dd1..6e00126ce6 100644
--- a/NEWS
+++ b/NEWS
@@ -71,6 +71,8 @@ PHP NEWS
. Fixed bug #73265 (Loading browscap.ini at startup causes high memory usage).
(Nikita)
. Add subject to mail log. (tomsommer)
+ . Fixed bug #31875 (get_defined_functions additional param to exclude
+ disabled functions). (willianveiga)
- Zlib
. Fixed bug #73373 (deflate_add does not verify that output was not truncated).
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 0fb0036b7f..f81f10ce8c 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -1947,13 +1947,22 @@ static int copy_function_name(zval *zv, int num_args, va_list args, zend_hash_ke
zend_function *func = Z_PTR_P(zv);
zval *internal_ar = va_arg(args, zval *),
*user_ar = va_arg(args, zval *);
+ zend_bool *exclude_disabled = va_arg(args, zend_bool *);
if (hash_key->key == NULL || ZSTR_VAL(hash_key->key)[0] == 0) {
return 0;
}
if (func->type == ZEND_INTERNAL_FUNCTION) {
- add_next_index_str(internal_ar, zend_string_copy(hash_key->key));
+ char *disable_functions = INI_STR("disable_functions");
+
+ if ((*exclude_disabled == 1) && (disable_functions != NULL)) {
+ if (strstr(disable_functions, func->common.function_name->val) == NULL) {
+ add_next_index_str(internal_ar, zend_string_copy(hash_key->key));
+ }
+ } else {
+ add_next_index_str(internal_ar, zend_string_copy(hash_key->key));
+ }
} else if (func->type == ZEND_USER_FUNCTION) {
add_next_index_str(user_ar, zend_string_copy(hash_key->key));
}
@@ -1967,8 +1976,9 @@ static int copy_function_name(zval *zv, int num_args, va_list args, zend_hash_ke
ZEND_FUNCTION(get_defined_functions)
{
zval internal, user;
+ zend_bool exclude_disabled = 0;
- if (zend_parse_parameters_none() == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &exclude_disabled) == FAILURE) {
return;
}
@@ -1976,7 +1986,7 @@ ZEND_FUNCTION(get_defined_functions)
array_init(&user);
array_init(return_value);
- zend_hash_apply_with_arguments(EG(function_table), copy_function_name, 2, &internal, &user);
+ zend_hash_apply_with_arguments(EG(function_table), copy_function_name, 3, &internal, &user, &exclude_disabled);
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal);
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user);
diff --git a/tests/basic/bug31875.phpt b/tests/basic/bug31875.phpt
new file mode 100644
index 0000000000..78085d766b
--- /dev/null
+++ b/tests/basic/bug31875.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug #31875 get_defined_functions() should not list disabled functions
+--CREDITS--
+Willian Gustavo Veiga <contact@willianveiga.com>
+--INI--
+disable_functions=dl
+--FILE--
+<?php
+$disabled_function = 'dl';
+
+$functions = get_defined_functions();
+var_dump(in_array($disabled_function, $functions['internal']));
+
+$functions = get_defined_functions(false);
+var_dump(in_array($disabled_function, $functions['internal']));
+
+$functions = get_defined_functions(true);
+var_dump(in_array($disabled_function, $functions['internal']));
+?>
+--EXPECTF--
+bool(true)
+bool(true)
+bool(false)