From e2fcff332f4e64349037c5947adaa813d50dccd7 Mon Sep 17 00:00:00 2001 From: DVenckus Date: Fri, 17 Jan 2020 22:37:45 -0600 Subject: [PATCH 1/6] php7.3 compatibility with php7.3 --- backtrace.c | 78 ++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/backtrace.c b/backtrace.c index 692a1a5..56aed55 100644 --- a/backtrace.c +++ b/backtrace.c @@ -387,29 +387,29 @@ static void append_flat_zval_r(zval *expr TSRMLS_DC, smart_str *trace_str, char #endif case IS_ARRAY: smart_str_appendc(trace_str, '['); -#if PHP_VERSION_ID >= 70000 - if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) && ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) { -#else - if (++Z_ARRVAL_P(expr)->nApplyCount>1) { -#endif - smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); -#if PHP_VERSION_ID >= 70000 - Z_ARRVAL_P(expr)->u.v.nApplyCount--; -#else - Z_ARRVAL_P(expr)->nApplyCount--; -#endif - return; - } +// #if PHP_VERSION_ID >= 70000 +// if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) && ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) { +// #else +// if (++Z_ARRVAL_P(expr)->nApplyCount>1) { +// #endif +// smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); +// #if PHP_VERSION_ID >= 70000 +// Z_ARRVAL_P(expr)->u.v.nApplyCount--; +// #else +// Z_ARRVAL_P(expr)->nApplyCount--; +// #endif +// return; +// } append_flat_hash(Z_ARRVAL_P(expr) TSRMLS_CC, trace_str, 0, depth + 1); smart_str_appendc(trace_str, ']'); -#if PHP_VERSION_ID >= 70000 - if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) { - Z_ARRVAL_P(expr)->u.v.nApplyCount--; - } -#else - Z_ARRVAL_P(expr)->nApplyCount--; -#endif - break; +// #if PHP_VERSION_ID >= 70000 +// if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) { +// Z_ARRVAL_P(expr)->u.v.nApplyCount--; +// } +// #else +// Z_ARRVAL_P(expr)->nApplyCount--; +// #endif +// break; case IS_OBJECT: { HashTable *properties = NULL; @@ -419,10 +419,10 @@ static void append_flat_zval_r(zval *expr TSRMLS_DC, smart_str *trace_str, char smart_str_appendl(trace_str, " Object (", sizeof(" Object (") - 1); zend_string_release(class_name); - if (Z_OBJ_APPLY_COUNT_P(expr) > 0) { - smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); - return; - } + // if (Z_OBJ_APPLY_COUNT_P(expr) > 0) { + // smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); + // return; + // } #else char *class_name = NULL; zend_uint clen; @@ -443,21 +443,21 @@ static void append_flat_zval_r(zval *expr TSRMLS_DC, smart_str *trace_str, char properties = Z_OBJPROP_P(expr); } if (properties) { -#if PHP_VERSION_ID >= 70000 - Z_OBJ_INC_APPLY_COUNT_P(expr); -#else - if (++properties->nApplyCount>1) { - smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); - properties->nApplyCount--; - return; - } -#endif +// #if PHP_VERSION_ID >= 70000 +// Z_OBJ_INC_APPLY_COUNT_P(expr); +// #else +// if (++properties->nApplyCount>1) { +// smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); +// properties->nApplyCount--; +// return; +// } +// #endif append_flat_hash(properties TSRMLS_CC, trace_str, 1, depth + 1); -#if PHP_VERSION_ID >= 70000 - Z_OBJ_DEC_APPLY_COUNT_P(expr); -#else - properties->nApplyCount--; -#endif +// #if PHP_VERSION_ID >= 70000 +// Z_OBJ_DEC_APPLY_COUNT_P(expr); +// #else +// properties->nApplyCount--; +// #endif } smart_str_appendc(trace_str, ')'); break; From 57a4a6d0ad876665ac1d35d6505c1301dff16969 Mon Sep 17 00:00:00 2001 From: DVenckus Date: Sat, 18 Jan 2020 10:53:18 -0600 Subject: [PATCH 2/6] php7.3 correct missing 'break;' stmt --- backtrace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backtrace.c b/backtrace.c index 56aed55..2c77e23 100644 --- a/backtrace.c +++ b/backtrace.c @@ -392,7 +392,7 @@ static void append_flat_zval_r(zval *expr TSRMLS_DC, smart_str *trace_str, char // #else // if (++Z_ARRVAL_P(expr)->nApplyCount>1) { // #endif -// smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); + // smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); // #if PHP_VERSION_ID >= 70000 // Z_ARRVAL_P(expr)->u.v.nApplyCount--; // #else @@ -409,7 +409,7 @@ static void append_flat_zval_r(zval *expr TSRMLS_DC, smart_str *trace_str, char // #else // Z_ARRVAL_P(expr)->nApplyCount--; // #endif -// break; + break; case IS_OBJECT: { HashTable *properties = NULL; From c2341a60837313d3772c6db49487dda377bcd15e Mon Sep 17 00:00:00 2001 From: DVenckus Date: Sat, 18 Jan 2020 11:00:08 -0600 Subject: [PATCH 3/6] php7.3 include additional files to ignore from build --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 5546db5..2cd8278 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ mkinstalldirs modules/ run-tests.php *.lo +/apm.ini.* +/config.log +/configure.ac From 02e5d679894a374da30c3890b16590de439536da Mon Sep 17 00:00:00 2001 From: DVenckus Date: Sat, 18 Jan 2020 13:15:09 -0600 Subject: [PATCH 4/6] php7.3 re-instate conversion array/obj recursion protection (compat 7.3) --- backtrace.c | 141 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 103 insertions(+), 38 deletions(-) diff --git a/backtrace.c b/backtrace.c index 2c77e23..08d0aeb 100644 --- a/backtrace.c +++ b/backtrace.c @@ -42,6 +42,69 @@ static zval *debug_backtrace_get_args(void ***curpos TSRMLS_DC); static int append_variable(zval *expr, smart_str *trace_str); static char *apm_addslashes(char *str, uint length, int *new_length); + +#ifdef ZEND_HASH_GET_APPLY_COUNT /* PHP 7.2 or earlier recursion protection */ + + +inline static zend_bool php_apm_zend_hash_apply_protection(HashTable* ht) +{ + if (!ht) { + return 1; + } + if (ZEND_HASH_GET_APPLY_COUNT(ht) > 0) { + return 0; + } + if (ZEND_HASH_APPLY_PROTECTION(ht)) { + ZEND_HASH_INC_APPLY_COUNT(ht); + } + return 1; +} + +inline static zend_bool php_apm_zend_hash_apply_protection_end(HashTable* ht) +{ + if (!ht) { + return 1; + } + if (ZEND_HASH_GET_APPLY_COUNT(ht) == 0) { + return 0; + } + if (ZEND_HASH_APPLY_PROTECTION(ht)) { + ZEND_HASH_DEC_APPLY_COUNT(ht); + } + return 1; +} + + +#else /* PHP 7.3 or later */ + +inline static zend_bool php_apm_zend_hash_apply_protection_begin(zend_array* ht) +{ + if (GC_IS_RECURSIVE(ht)) { + return 0; + } + if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) { + GC_PROTECT_RECURSION(ht); + } + return 1; +} + +inline static zend_bool php_apm_zend_hash_apply_protection_end(zend_array* ht) +{ + if (!GC_IS_RECURSIVE(ht)) { + return 0; + } + if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) { + GC_UNPROTECT_RECURSION(ht); + } + return 1; +} + +#endif + + + + + void append_backtrace(smart_str *trace_str TSRMLS_DC) { /* backtrace variables */ @@ -387,28 +450,14 @@ static void append_flat_zval_r(zval *expr TSRMLS_DC, smart_str *trace_str, char #endif case IS_ARRAY: smart_str_appendc(trace_str, '['); -// #if PHP_VERSION_ID >= 70000 -// if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) && ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) { -// #else -// if (++Z_ARRVAL_P(expr)->nApplyCount>1) { -// #endif - // smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); -// #if PHP_VERSION_ID >= 70000 -// Z_ARRVAL_P(expr)->u.v.nApplyCount--; -// #else -// Z_ARRVAL_P(expr)->nApplyCount--; -// #endif -// return; -// } + if ( php_apm_zend_hash_apply_protection_begin(Z_ARRVAL_P(expr)) ) { + smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); + php_apm_zend_hash_apply_protection_end(Z_ARRVAL_P(expr)); + return; + } append_flat_hash(Z_ARRVAL_P(expr) TSRMLS_CC, trace_str, 0, depth + 1); smart_str_appendc(trace_str, ']'); -// #if PHP_VERSION_ID >= 70000 -// if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) { -// Z_ARRVAL_P(expr)->u.v.nApplyCount--; -// } -// #else -// Z_ARRVAL_P(expr)->nApplyCount--; -// #endif + php_apm_zend_hash_apply_protection_end(Z_ARRVAL_P(expr)); break; case IS_OBJECT: { @@ -419,10 +468,15 @@ static void append_flat_zval_r(zval *expr TSRMLS_DC, smart_str *trace_str, char smart_str_appendl(trace_str, " Object (", sizeof(" Object (") - 1); zend_string_release(class_name); - // if (Z_OBJ_APPLY_COUNT_P(expr) > 0) { - // smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); - // return; - // } + #ifdef Z_IS_RECURSIVE_P + if (Z_IS_RECURSIVE_P(expr)) { + #else + if (Z_OBJ_APPLY_COUNT_P(expr) > 0) { + #endif + smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); + return; + } + #else char *class_name = NULL; zend_uint clen; @@ -439,25 +493,34 @@ static void append_flat_zval_r(zval *expr TSRMLS_DC, smart_str *trace_str, char efree(class_name); } #endif + if (Z_OBJ_HANDLER_P(expr, get_properties)) { properties = Z_OBJPROP_P(expr); } if (properties) { -// #if PHP_VERSION_ID >= 70000 -// Z_OBJ_INC_APPLY_COUNT_P(expr); -// #else -// if (++properties->nApplyCount>1) { -// smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); -// properties->nApplyCount--; -// return; -// } -// #endif +#if PHP_VERSION_ID >= 70000 + #ifdef Z_IS_RECURSIVE_P + Z_PROTECT_RECURSION_P(expr); + #else + Z_OBJ_INC_APPLY_COUNT_P(expr); + #endif +#else + if (++properties->nApplyCount>1) { + smart_str_appendl(trace_str, " *RECURSION*", sizeof(" *RECURSION*") - 1); + properties->nApplyCount--; + return; + } +#endif append_flat_hash(properties TSRMLS_CC, trace_str, 1, depth + 1); -// #if PHP_VERSION_ID >= 70000 -// Z_OBJ_DEC_APPLY_COUNT_P(expr); -// #else -// properties->nApplyCount--; -// #endif +#if PHP_VERSION_ID >= 70000 + #ifdef Z_IS_RECURSIVE_P + Z_UNPROTECT_RECURSION_P(expr); + #else + Z_OBJ_DEC_APPLY_COUNT_P(expr); + #endif +#else + properties->nApplyCount--; +#endif } smart_str_appendc(trace_str, ')'); break; @@ -468,6 +531,8 @@ static void append_flat_zval_r(zval *expr TSRMLS_DC, smart_str *trace_str, char } } + + static void append_flat_hash(HashTable *ht TSRMLS_DC, smart_str *trace_str, char is_object, char depth) { int i = 0; From 755a6d46133f5d617d4bf6ab6210bc5e1c218c2e Mon Sep 17 00:00:00 2001 From: DVenckus Date: Sat, 18 Jan 2020 13:33:07 -0600 Subject: [PATCH 5/6] php7.3 add missed function declarations --- backtrace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backtrace.c b/backtrace.c index 08d0aeb..1389bf2 100644 --- a/backtrace.c +++ b/backtrace.c @@ -29,6 +29,8 @@ ZEND_DECLARE_MODULE_GLOBALS(apm); +inline static zend_bool php_apm_zend_hash_apply_protection_begin(HashTable* ht); +inline static zend_bool php_apm_zend_hash_apply_protection_end(HashTable* ht) static void debug_print_backtrace_args(zval *arg_array TSRMLS_DC, smart_str *trace_str); static void append_flat_zval_r(zval *expr TSRMLS_DC, smart_str *trace_str, char depth); static void append_flat_hash(HashTable *ht TSRMLS_DC, smart_str *trace_str, char is_object, char depth); @@ -46,7 +48,7 @@ static char *apm_addslashes(char *str, uint length, int *new_length); #ifdef ZEND_HASH_GET_APPLY_COUNT /* PHP 7.2 or earlier recursion protection */ -inline static zend_bool php_apm_zend_hash_apply_protection(HashTable* ht) +inline static zend_bool php_apm_zend_hash_apply_protection_begin(HashTable* ht) { if (!ht) { return 1; From 4a9512820bca65b712046eee1ef2ff7c1cd4654c Mon Sep 17 00:00:00 2001 From: DVenckus Date: Sat, 18 Jan 2020 14:03:50 -0600 Subject: [PATCH 6/6] php7.3 dagnabbit! --- backtrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backtrace.c b/backtrace.c index 1389bf2..d622dd8 100644 --- a/backtrace.c +++ b/backtrace.c @@ -30,7 +30,7 @@ ZEND_DECLARE_MODULE_GLOBALS(apm); inline static zend_bool php_apm_zend_hash_apply_protection_begin(HashTable* ht); -inline static zend_bool php_apm_zend_hash_apply_protection_end(HashTable* ht) +inline static zend_bool php_apm_zend_hash_apply_protection_end(HashTable* ht); static void debug_print_backtrace_args(zval *arg_array TSRMLS_DC, smart_str *trace_str); static void append_flat_zval_r(zval *expr TSRMLS_DC, smart_str *trace_str, char depth); static void append_flat_hash(HashTable *ht TSRMLS_DC, smart_str *trace_str, char is_object, char depth);