From 3cdc0776a592d06d234838829a8d81c8f2c22899 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Fri, 5 Jul 2024 02:29:27 +0200 Subject: [PATCH] Fix post bailout hook execution in 8.3 unoptimized builds (#2737) When optimized, all is fine; however, in unoptimized builds the compiler will write stacktarget back to the stack and read it later from there, even though the stack address has moved. (i.e. only affects development builds.) Adding register keyword to avoid this. --- zend_abstract_interface/interceptor/php8/interceptor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zend_abstract_interface/interceptor/php8/interceptor.c b/zend_abstract_interface/interceptor/php8/interceptor.c index c499308155..fdbbdfe4af 100644 --- a/zend_abstract_interface/interceptor/php8/interceptor.c +++ b/zend_abstract_interface/interceptor/php8/interceptor.c @@ -63,7 +63,11 @@ static void zai_hook_safe_finish(zend_execute_data *execute_data, zval *retval, const size_t stack_top_offset = 0x400; void *volatile stack = malloc(stack_size); if (SETJMP(target) == 0) { - void *stacktop = stack + stack_size, *stacktarget = stacktop - stack_top_offset; + void *stacktop = stack + stack_size; +#if PHP_VERSION_ID >= 80300 + register +#endif + void *stacktarget = stacktop - stack_top_offset; #ifdef __SANITIZE_ADDRESS__ void *volatile fake_stack;