2424#include "zend_compile.h"
2525#include "zend_hash.h"
2626#include "zend_operators.h"
27+ #include "zend_types.h"
2728#include "zend_variables.h"
2829#include "zend_constants.h"
30+ #include "zend_asan.h"
2931
3032#include <stdint.h>
3133
@@ -322,6 +324,7 @@ static zend_always_inline zend_vm_stack zend_vm_stack_new_page(size_t size, zend
322324 page -> top = ZEND_VM_STACK_ELEMENTS (page );
323325 page -> end = (zval * )((char * )page + size );
324326 page -> prev = prev ;
327+ ZEND_POISON_MEMORY_REGION (page -> top , (uintptr_t )page -> end - (uintptr_t )page -> top );
325328 return page ;
326329}
327330
@@ -342,11 +345,13 @@ static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame_ex(ui
342345
343346 if (UNEXPECTED (used_stack > (size_t )(((char * )EG (vm_stack_end )) - (char * )call ))) {
344347 call = (zend_execute_data * )zend_vm_stack_extend (used_stack );
348+ ZEND_UNPOISON_MEMORY_REGION (call , used_stack );
345349 ZEND_ASSERT_VM_STACK_GLOBAL ;
346350 zend_vm_init_call_frame (call , call_info | ZEND_CALL_ALLOCATED , func , num_args , object_or_called_scope );
347351 return call ;
348352 } else {
349353 EG (vm_stack_top ) = (zval * )((char * )call + used_stack );
354+ ZEND_UNPOISON_MEMORY_REGION (call , used_stack );
350355 zend_vm_init_call_frame (call , call_info , func , num_args , object_or_called_scope );
351356 return call ;
352357 }
@@ -370,6 +375,21 @@ static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame(uint3
370375 func , num_args , object_or_called_scope );
371376}
372377
378+ static zend_always_inline zend_execute_data * zend_vm_stack_pop_call_frame (zend_execute_data * execute_data )
379+ {
380+ #ifdef __SANITIZE_ADDRESS__
381+ zend_execute_data * prev_execute_data = execute_data -> prev_execute_data ;
382+
383+ ZEND_POISON_MEMORY_REGION (execute_data , (uintptr_t )EG (vm_stack_top ) - (uintptr_t )execute_data );
384+ EG (vm_stack_top ) = (zval * )execute_data ;
385+
386+ return prev_execute_data ;
387+ #else
388+ EG (vm_stack_top ) = (zval * )execute_data ;
389+ return execute_data -> prev_execute_data ;
390+ #endif
391+ }
392+
373393static zend_always_inline void zend_vm_stack_free_extra_args_ex (uint32_t call_info , zend_execute_data * call )
374394{
375395 if (UNEXPECTED (call_info & ZEND_CALL_FREE_EXTRA_ARGS )) {
@@ -415,6 +435,7 @@ static zend_always_inline void zend_vm_stack_free_call_frame_ex(uint32_t call_in
415435 EG (vm_stack ) = prev ;
416436 efree (p );
417437 } else {
438+ ZEND_POISON_MEMORY_REGION (call , (uintptr_t )EG (vm_stack_top ) - (uintptr_t )call );
418439 EG (vm_stack_top ) = (zval * )call ;
419440 }
420441
@@ -433,6 +454,7 @@ static zend_always_inline void zend_vm_stack_extend_call_frame(
433454 zend_execute_data * * call , uint32_t passed_args , uint32_t additional_args )
434455{
435456 if (EXPECTED ((uint32_t )(EG (vm_stack_end ) - EG (vm_stack_top )) > additional_args )) {
457+ ZEND_UNPOISON_MEMORY_REGION (EG (vm_stack_top ), additional_args * sizeof (zval ));
436458 EG (vm_stack_top ) += additional_args ;
437459 } else {
438460 * call = zend_vm_stack_copy_call_frame (* call , passed_args , additional_args );
0 commit comments