From 7a79e03031bc8d45722aa77a3219c27b1035760d Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 7 Oct 2024 13:30:14 -0300 Subject: [PATCH 1/3] Fix regression on platforms without ZEND_CHECK_STACK_LIMIT set There was a guard on one instance of this, but not the other. Unsure if this is the best place for this; the functions are `#ifdef` gated in `zend_execute.c`, but not the associated header; perhaps it should be `#else` with a nop version of the function in that case? I added a guard at this call site to be consistent with other places. --- ext/standard/var.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/standard/var.c b/ext/standard/var.c index 248bf086c3caf..f16b4d31ab656 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -1052,7 +1052,9 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_ } if (UNEXPECTED(php_serialize_check_stack_limit())) { +#ifdef ZEND_CHECK_STACK_LIMIT zend_call_stack_size_error(); +#endif return; } From d8adb0173e719230569cc87d9f82b8a0bfc700db Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 7 Oct 2024 14:26:12 -0300 Subject: [PATCH 2/3] Merge ifdef check for stack size check Co-authored-by: Arnaud Le Blanc --- ext/standard/var.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/standard/var.c b/ext/standard/var.c index f16b4d31ab656..db31854afe9ad 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -1036,7 +1036,10 @@ static void php_var_serialize_class(smart_str *buf, zval *struc, HashTable *ht, static zend_always_inline bool php_serialize_check_stack_limit(void) { #ifdef ZEND_CHECK_STACK_LIMIT - return zend_call_stack_overflowed(EG(stack_limit)); + if (UNEXPECTED(zend_call_stack_overflowed(EG(stack_limit)))) { + zend_call_stack_size_error(); + return true; + } #else return false; #endif @@ -1052,9 +1055,6 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_ } if (UNEXPECTED(php_serialize_check_stack_limit())) { -#ifdef ZEND_CHECK_STACK_LIMIT - zend_call_stack_size_error(); -#endif return; } From 1f39223d514e04cd3cf6eabaa143c36c2d22ac02 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 7 Oct 2024 15:46:47 -0300 Subject: [PATCH 3/3] Fix control flow by changing ifdef --- ext/standard/var.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/standard/var.c b/ext/standard/var.c index db31854afe9ad..1c2b0eb164a1c 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -1040,9 +1040,8 @@ static zend_always_inline bool php_serialize_check_stack_limit(void) zend_call_stack_size_error(); return true; } -#else - return false; #endif + return false; } static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_data_t var_hash, bool in_rcn_array, bool is_root) /* {{{ */