diff --git a/appsec/src/extension/php_compat.c b/appsec/src/extension/php_compat.c index f4f8ddce870..608b16d097b 100644 --- a/appsec/src/extension/php_compat.c +++ b/appsec/src/extension/php_compat.c @@ -6,6 +6,13 @@ #include "php_compat.h" #if PHP_VERSION_ID < 70300 +static zend_string _zend_empty_string_st = { + .gc.refcount = 1, + .gc.u.v.type = IS_STRING, + .gc.u.v.flags = IS_STR_PERSISTENT | IS_STR_INTERNED, +}; +zend_string *zend_empty_string = &_zend_empty_string_st; + zend_bool zend_ini_parse_bool(zend_string *str) { if ((ZSTR_LEN(str) == 4 && strcasecmp(ZSTR_VAL(str), "true") == 0) || diff --git a/appsec/src/extension/php_compat.h b/appsec/src/extension/php_compat.h index abd3205d528..14be5aa73b6 100644 --- a/appsec/src/extension/php_compat.h +++ b/appsec/src/extension/php_compat.h @@ -43,6 +43,7 @@ static zend_always_inline zend_string *zend_string_init_interned( return zend_new_interned_string(ret); # endif } +extern zend_string *zend_empty_string; #endif #if PHP_VERSION_ID < 70300 diff --git a/appsec/src/extension/request_abort.c b/appsec/src/extension/request_abort.c index 08b8744666e..0f0ed713731 100644 --- a/appsec/src/extension/request_abort.c +++ b/appsec/src/extension/request_abort.c @@ -67,7 +67,6 @@ static zend_string *_content_length_zstr; static zend_string *_location_zstr; static zend_string *_content_type_html_zstr; static zend_string *_content_type_json_zstr; -static zend_string *_empty_zstr; // older versions don't have zend_empty_string static THREAD_LOCAL_ON_ZTS int _response_code = DEFAULT_BLOCKING_RESPONSE_CODE; static THREAD_LOCAL_ON_ZTS dd_response_type _response_type = DEFAULT_RESPONSE_TYPE; @@ -107,7 +106,7 @@ static zend_string *nullable _read_file_contents(const char *nonnull path) php_stream_close(fs); if (!contents) { - return _empty_zstr; + return zend_empty_string; } return contents; } @@ -600,7 +599,6 @@ void dd_request_abort_startup() zend_string_init_interned(ZEND_STRL(HTML_CONTENT_TYPE), 1); _content_type_json_zstr = zend_string_init_interned(ZEND_STRL(JSON_CONTENT_TYPE), 1); - _empty_zstr = zend_string_init_interned(&(char){0}, 0, 1); if (!get_global_DD_APPSEC_TESTING()) { return; @@ -620,7 +618,7 @@ static zend_string *nonnull _get_json_blocking_template() // * if the template file is not found, return an empty template // * if the template file is empty, return the default if (!body_error_json) { - return _empty_zstr; + return zend_empty_string; } if (ZSTR_LEN(body_error_json) == 0) { zend_string_release(body_error_json); @@ -641,7 +639,7 @@ static zend_string *nonnull _get_html_blocking_template() zend_string *nullable body_error_html = _read_file_contents(ZSTR_VAL(html_template_file)); if (!body_error_html) { - return _empty_zstr; + return zend_empty_string; } if (ZSTR_LEN(body_error_html) == 0) { zend_string_release(body_error_html);