[php-src] PR #12275: Set func pointer to null in Closure __invoke

From: Date: Fri, 22 Sep 2023 18:12:00 +0000
Subject: [php-src] PR #12275: Set func pointer to null in Closure __invoke
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-23670@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/12275 Author: morrisonlevi I've written the comment as if it's happened and been agreed to, but I want to have a little bit of discussion here. The only reason I can think of for this to not be done unconditionally, is something like this: Detect detect use-after-frees in this code in non-debug asan builds, and avoid the absolutely minuscule cost of setting it to null in release builds. This means that we would want to be sure that literally everything in the engine and the entire ecosystem should _know_ this is an invalid pointer even though it's not null. For instance: ```c void (*og_zend_execute_internal)(zend_execute_data *execute_data, zval *return_value); void my_extension_execute_internal(zend_execute_data *execute_data, zval *return_value) { og_zend_execute_internal(execute_data, return_value); // know that execute_data->func may be non-null but invalid. } ``` That seems like a stretch. Of course, I did not know this and a customer hit this in production, causing a crash. I think it would be best to set this to null, rather than requiring them to do something like: ```c void my_extension_execute_internal(zend_execute_data *execute_data, zval *return_value) { bool is_trampoline = execute_data && execute_data->func && (execute_data->func->common.flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0; og_zend_execute_internal(execute_data, return_value); if (is_trampoline) { // know that you cannot touch execute_data->func } } ``` Note that observers avoid this because the end observer is skipped in cases like this. Maybe @bwoebi can provide a more detailed explanation there.

« previous php.git-pulls (#23670) next »