Skip to content

Commit

Permalink
Provide zend_empty_string for compat
Browse files Browse the repository at this point in the history
  • Loading branch information
cataphract committed Jun 27, 2024
1 parent ee07350 commit d91cd3f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 7 additions & 0 deletions appsec/src/extension/php_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down
1 change: 1 addition & 0 deletions appsec/src/extension/php_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions appsec/src/extension/request_abort.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit d91cd3f

Please sign in to comment.