Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Zend/tests/call_user_functions/call_user_func_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ try {
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
call_user_func(array('\\', 'bar'));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
call_user_func(array($foo, 'bar'));
} catch (Throwable $e) {
Expand All @@ -33,6 +38,7 @@ try {
string(3) "foo"
TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, class "foo" not found
TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, class "" not found
TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, class "\" not found

Warning: Undefined variable $foo in %s on line %d
TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, first array member is not a valid class name or object
Expand Down
25 changes: 21 additions & 4 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -3743,8 +3743,25 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
zend_string *lcname;
ALLOCA_FLAG(use_heap);

ZSTR_ALLOCA_ALLOC(lcname, name_len, use_heap);
zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(name), name_len);
if (UNEXPECTED(ZSTR_LEN(name) == 0)) {
if (error) {
*error = estrdup("class \"\" not found");
}
return false;
}
if (ZSTR_VAL(name)[0] == '\\') {
if (UNEXPECTED(ZSTR_LEN(name) == 1)) {
if (error) {
*error = estrdup("class \"\\\" not found");
}
return false;
}
ZSTR_ALLOCA_ALLOC(lcname, name_len-1, use_heap);
zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(name)+1, name_len-1);
} else {
ZSTR_ALLOCA_ALLOC(lcname, name_len, use_heap);
zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(name), name_len);
}

*strict_class = false;
if (zend_string_equals(lcname, ZSTR_KNOWN(ZEND_STR_SELF))) {
Expand Down Expand Up @@ -3801,7 +3818,7 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
*strict_class = true;
ret = true;
}
} else if ((ce = zend_lookup_class(name)) != NULL) {
} else if ((ce = zend_lookup_class_ex(name, lcname, 0)) != NULL) {
const zend_class_entry *frame_scope = get_scope(frame);
fcc->calling_scope = ce;
if (frame_scope && !fcc->object) {
Expand All @@ -3821,7 +3838,7 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
*strict_class = true;
ret = true;
} else {
if (error) zend_spprintf(error, 0, "class \"%.*s\" not found", (int)name_len, ZSTR_VAL(name));
if (error) zend_spprintf(error, 0, "class \"%pS\" not found", name);
}
ZSTR_ALLOCA_FREE(lcname, use_heap);
/* User error handlers may throw from deprecations above; do not report callable as valid. */
Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,8 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *
}

if (key) {
ZEND_ASSERT(ZSTR_LEN(name) != 0 && "Must not be an empty class name");
ZEND_ASSERT((ZSTR_VAL(name)[0] != '\\' || ZSTR_LEN(name) > 1) && "Class name must not be \"\\\"");
lc_name = key;
} else {
if (!ZSTR_LEN(name)) {
Expand Down
Loading