From 27075ad33cabb7a69cfe4ce55d516a15354b62a4 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 25 Feb 2023 18:00:05 +0100 Subject: [PATCH 1/3] Remove always-false check in zend_lookup_class_ex() This check is always false because of the undefined behaviour rule that says a NULL pointer must never be dereferenced: we already dereference name when checking the cache slot, before the NULL check. So the NULL may be optimised away by the compiler. It looks like the code isn't even supposed to work with name being NULL, so just remove the check. --- Zend/zend_execute_API.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index efdebc6498a0e..c279cdc3caff5 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -1115,7 +1115,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string * if (key) { lc_name = key; } else { - if (name == NULL || !ZSTR_LEN(name)) { + if (!ZSTR_LEN(name)) { return NULL; } From 90d64990766d471dc6d6369c70aef0535bf05ce8 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 25 Feb 2023 18:02:15 +0100 Subject: [PATCH 2/3] Remove always-true check in zend_fetch_static_property_address_ex() --- Zend/zend_execute.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index a2d7e8f2aaf20..e15469c539e95 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -3365,11 +3365,9 @@ static zend_never_inline zend_result zend_fetch_static_property_address_ex(zval } *retval = zend_std_get_static_property_with_info(ce, name, fetch_type, &property_info); - if (UNEXPECTED(op1_type != IS_CONST)) { - zend_tmp_string_release(tmp_name); + zend_tmp_string_release(tmp_name); - FREE_OP(op1_type, opline->op1.var); - } + FREE_OP(op1_type, opline->op1.var); } if (UNEXPECTED(*retval == NULL)) { From 2b12531f4dbd6835e96cbf56bc531f158fc9ebc5 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 25 Feb 2023 21:18:12 +0100 Subject: [PATCH 3/3] Simplify always-true conditions --- Zend/zend_API.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index a066f657f3b80..3e9aaed418095 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2749,7 +2749,7 @@ ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend if (ptr->flags) { if (!(ptr->flags & ZEND_ACC_PPP_MASK)) { if (ptr->flags != ZEND_ACC_DEPRECATED && scope) { - zend_error(error_type, "Invalid access level for %s%s%s() - access must be exactly one of public, protected or private", scope ? ZSTR_VAL(scope->name) : "", scope ? "::" : "", ptr->fname); + zend_error(error_type, "Invalid access level for %s::%s() - access must be exactly one of public, protected or private", ZSTR_VAL(scope->name), ptr->fname); } internal_function->fn_flags = ZEND_ACC_PUBLIC | ptr->flags; } else { @@ -3797,9 +3797,9 @@ static zend_always_inline bool zend_is_callable_check_func(zval *callable, zend_ } } else if (error) { if (fcc->calling_scope) { - if (error) zend_spprintf(error, 0, "class %s does not have a method \"%s\"", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(mname)); + zend_spprintf(error, 0, "class %s does not have a method \"%s\"", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(mname)); } else { - if (error) zend_spprintf(error, 0, "function %s() does not exist", ZSTR_VAL(mname)); + zend_spprintf(error, 0, "function %s() does not exist", ZSTR_VAL(mname)); } } zend_string_release_ex(lmname, 0);