Skip to content

Commit b8e7b30

Browse files
committed
Fix #79668: get_defined_functions(true) may miss functions
Instead of some brittle and unefficient string matching, we can just check for the function handler.
1 parent 63bd8f3 commit b8e7b30

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PHP NEWS
44

55
- Core:
66
. Fixed bug #79650 (php-win.exe 100% cpu lockup). (cmb)
7+
. Fixed bug #79668 (get_defined_functions(true) may miss functions). (cmb,
8+
Nikita)
79

810
- PDO SQLite:
911
. Fixed bug #79664 (PDOStatement::getColumnMeta fails on empty result set).

Zend/tests/bug79668.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #79668 (get_defined_functions(true) may miss functions)
3+
--INI--
4+
disable_functions=sha1_file,password_hash
5+
--FILE--
6+
<?php
7+
$df = get_defined_functions(true);
8+
foreach (['sha1', 'sha1_file', 'hash', 'password_hash'] as $funcname) {
9+
var_dump(in_array($funcname, $df['internal'], true));
10+
}
11+
?>
12+
--EXPECT--
13+
bool(true)
14+
bool(false)
15+
bool(true)
16+
bool(false)

Zend/zend_builtin_functions.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,16 +1847,9 @@ static int copy_function_name(zval *zv, int num_args, va_list args, zend_hash_ke
18471847
return 0;
18481848
}
18491849

1850-
if (func->type == ZEND_INTERNAL_FUNCTION) {
1851-
char *disable_functions = INI_STR("disable_functions");
1852-
1853-
if ((*exclude_disabled == 1) && (disable_functions != NULL)) {
1854-
if (strstr(disable_functions, func->common.function_name->val) == NULL) {
1855-
add_next_index_str(internal_ar, zend_string_copy(hash_key->key));
1856-
}
1857-
} else {
1858-
add_next_index_str(internal_ar, zend_string_copy(hash_key->key));
1859-
}
1850+
if (func->type == ZEND_INTERNAL_FUNCTION
1851+
&& (!*exclude_disabled || func->internal_function.handler != ZEND_FN(display_disabled_function))) {
1852+
add_next_index_str(internal_ar, zend_string_copy(hash_key->key));
18601853
} else if (func->type == ZEND_USER_FUNCTION) {
18611854
add_next_index_str(user_ar, zend_string_copy(hash_key->key));
18621855
}

0 commit comments

Comments
 (0)