Repository navigation
Fix GH-24430: Check for user frame before reading opline in generator dtor - #25278
Open
prateekbhujel wants to merge 1 commit into
Open
prateekbhujel wants to merge 1 commit into
prateekbhujel wants to merge 1 commit into
Conversation
…tor dtor When zend_generator_dtor_storage() runs finally blocks while an exception is already pending (such as when an earlier generator's finally block threw during gc_collect_cycles()), EG(current_execute_data) can be an internal function frame like gc_destructor_fiber() whose opline slot on the VM stack is uninitialized. Check that EG(current_execute_data)->func is user code before dereferencing EG(current_execute_data)->opline->opcode, matching is_handle_exception_set(). Fixes phpGH-24430
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes GH-24430
When
zend_generator_dtor_storage()executes a generator'sfinallyblock whileEG(exception)is already set (for example, when an earlier generator'sfinallyblock threw duringgc_collect_cycles()inside a fiber),EG(current_execute_data)is thegc_destructor_fiber()internal function frame.Because
zend_vm_init_call_frame()does not initializecall->oplinefor internal function frames,EG(current_execute_data)->oplinecontains uninitialized stack memory when the fiber VM stack page is allocated from dirty heap memory or under AddressSanitizer. ReadingEG(current_execute_data)->opline->opcodewithout first checkingEG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type)then dereferences an uninitialized pointer.Guard the
oplinecheck withEG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type), matchingis_handle_exception_set()inZend/zend_exceptions.c.cc @alexandre-daubois @iluuu1994