Skip to content

Commit

Permalink
make appsec compile with PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
realFlowControl committed Jul 17, 2024
1 parent fd9c2eb commit 47dcd62
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 34 deletions.
2 changes: 1 addition & 1 deletion appsec/src/extension/commands_ctx.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "attributes.h"
#include <php.h>
#include "attributes.h"

struct req_info {
const char *nullable command_name; // for logging
Expand Down
2 changes: 1 addition & 1 deletion appsec/src/extension/commands_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
#pragma once

#include "attributes.h"
#include "commands_ctx.h"
#include "attributes.h"
#include "dddefs.h"
#include "network.h"
#include <mpack.h>
Expand Down
11 changes: 11 additions & 0 deletions appsec/src/extension/compatibility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef DD_COMPATIBILITY_H
#define DD_COMPATIBILITY_H

#include <php.h>

#if PHP_VERSION_ID < 80400
#undef ZEND_RAW_FENTRY
#define ZEND_RAW_FENTRY(zend_name, name, arg_info, flags, ...) { zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_internal_arg_info)-1), flags },
#endif

#endif // DD_COMPATIBILITY_H
6 changes: 4 additions & 2 deletions appsec/src/extension/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "tags.h"
#include "zai_string/string.h"

#include "compatibility.h"

#define DD_TO_DATADOG_INC 5 /* "DD" expanded to "datadog" */

#define APPLY_0(...)
Expand Down Expand Up @@ -285,8 +287,8 @@ ZEND_END_ARG_INFO()

// clang-format off
static const zend_function_entry testing_functions[] = {
ZEND_RAW_FENTRY(DD_TESTING_NS "zai_config_get_value", PHP_FN(datadog_appsec_testing_zai_config_get_value), set_string_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "zai_config_get_global_value", PHP_FN(datadog_appsec_testing_zai_config_get_global_value), set_string_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "zai_config_get_value", PHP_FN(datadog_appsec_testing_zai_config_get_value), set_string_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "zai_config_get_global_value", PHP_FN(datadog_appsec_testing_zai_config_get_global_value), set_string_arginfo, 0, NULL, NULL)
PHP_FE_END
};
// clang-format on
Expand Down
15 changes: 8 additions & 7 deletions appsec/src/extension/ddappsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "commands/request_init.h"
#include "commands/request_shutdown.h"
#include "commands_ctx.h"
#include "compatibility.h"
#include "configuration.h"
#include "ddappsec.h"
#include "dddefs.h"
Expand Down Expand Up @@ -516,16 +517,16 @@ ZEND_END_ARG_INFO()

// clang-format off
static const zend_function_entry functions[] = {
ZEND_RAW_FENTRY(DD_APPSEC_NS "is_enabled", PHP_FN(datadog_appsec_is_enabled), void_ret_bool_arginfo, 0)
ZEND_RAW_FENTRY(DD_APPSEC_NS "push_address", PHP_FN(datadog_appsec_push_address), push_address_arginfo, 0)
ZEND_RAW_FENTRY(DD_APPSEC_NS "is_enabled", PHP_FN(datadog_appsec_is_enabled), void_ret_bool_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_APPSEC_NS "push_address", PHP_FN(datadog_appsec_push_address), push_address_arginfo, 0, NULL, NULL)
PHP_FE_END
};
static const zend_function_entry testing_functions[] = {
ZEND_RAW_FENTRY(DD_TESTING_NS "rinit", PHP_FN(datadog_appsec_testing_rinit), void_ret_bool_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "rshutdown", PHP_FN(datadog_appsec_testing_rshutdown), void_ret_bool_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "helper_mgr_acquire_conn", PHP_FN(datadog_appsec_testing_helper_mgr_acquire_conn), void_ret_bool_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "stop_for_debugger", PHP_FN(datadog_appsec_testing_stop_for_debugger), void_ret_bool_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "request_exec", PHP_FN(datadog_appsec_testing_request_exec), request_exec_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "rinit", PHP_FN(datadog_appsec_testing_rinit), void_ret_bool_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "rshutdown", PHP_FN(datadog_appsec_testing_rshutdown), void_ret_bool_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "helper_mgr_acquire_conn", PHP_FN(datadog_appsec_testing_helper_mgr_acquire_conn), void_ret_bool_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "stop_for_debugger", PHP_FN(datadog_appsec_testing_stop_for_debugger), void_ret_bool_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "request_exec", PHP_FN(datadog_appsec_testing_request_exec), request_exec_arginfo, 0, NULL, NULL)
PHP_FE_END
};
// clang-format on
Expand Down
11 changes: 6 additions & 5 deletions appsec/src/extension/ddtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <fcntl.h>
#include <unistd.h>

#include "compatibility.h"
#include "configuration.h"
#include "ddappsec.h"
#include "logging.h"
Expand Down Expand Up @@ -459,11 +460,11 @@ ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0)
ZEND_END_ARG_INFO()

static const zend_function_entry functions[] = {
ZEND_RAW_FENTRY(DD_TESTING_NS "ddtrace_rshutdown", PHP_FN(datadog_appsec_testing_ddtrace_rshutdown), void_ret_bool_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_add_tag", PHP_FN(datadog_appsec_testing_root_span_add_tag), arginfo_root_span_add_tag, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_get_meta", PHP_FN(datadog_appsec_testing_root_span_get_meta), void_ret_nullable_array, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_get_metrics", PHP_FN(datadog_appsec_testing_root_span_get_metrics), void_ret_nullable_array, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "get_formatted_runtime_id", PHP_FN(datadog_appsec_testing_get_formatted_runtime_id), void_ret_nullable_string, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "ddtrace_rshutdown", PHP_FN(datadog_appsec_testing_ddtrace_rshutdown), void_ret_bool_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_add_tag", PHP_FN(datadog_appsec_testing_root_span_add_tag), arginfo_root_span_add_tag, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_get_meta", PHP_FN(datadog_appsec_testing_root_span_get_meta), void_ret_nullable_array, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "root_span_get_metrics", PHP_FN(datadog_appsec_testing_root_span_get_metrics), void_ret_nullable_array, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "get_formatted_runtime_id", PHP_FN(datadog_appsec_testing_get_formatted_runtime_id), void_ret_nullable_string, 0, NULL, NULL)
PHP_FE_END
};
// clang-format on
Expand Down
2 changes: 1 addition & 1 deletion appsec/src/extension/ddtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
#pragma once

#include "attributes.h"
#include <stdbool.h>
#include <zend.h>
#include "attributes.h"

static const int PRIORITY_SAMPLING_AUTO_KEEP = 1;
static const int PRIORITY_SAMPLING_AUTO_REJECT = 0;
Expand Down
11 changes: 6 additions & 5 deletions appsec/src/extension/helper_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <zend_types.h>

#define HELPER_PROCESS_C_INCLUDES
#include "compatibility.h"
#include "configuration.h"
#include "ddappsec.h"
#include "dddefs.h"
Expand Down Expand Up @@ -967,11 +968,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(void_ret_array_arginfo, 0, 0, IS_ARRAY,
ZEND_END_ARG_INFO()

static const zend_function_entry functions[] = {
ZEND_RAW_FENTRY(DD_TESTING_NS "set_helper_path", PHP_FN(datadog_appsec_testing_set_helper_path), set_string_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "set_helper_extra_args", PHP_FN(datadog_appsec_testing_set_helper_extra_args), set_string_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "get_helper_argv", PHP_FN(datadog_appsec_testing_get_helper_argv), void_ret_array_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "is_connected_to_helper", PHP_FN(datadog_appsec_testing_is_connected_to_helper), void_ret_bool_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "backoff_status", PHP_FN(datadog_appsec_testing_backoff_status), void_ret_array_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "set_helper_path", PHP_FN(datadog_appsec_testing_set_helper_path), set_string_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "set_helper_extra_args", PHP_FN(datadog_appsec_testing_set_helper_extra_args), set_string_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "get_helper_argv", PHP_FN(datadog_appsec_testing_get_helper_argv), void_ret_array_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "is_connected_to_helper", PHP_FN(datadog_appsec_testing_is_connected_to_helper), void_ret_bool_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "backoff_status", PHP_FN(datadog_appsec_testing_backoff_status), void_ret_array_arginfo, 0, NULL, NULL)
PHP_FE_END
};
// clang-format on
Expand Down
3 changes: 2 additions & 1 deletion appsec/src/extension/ip_extraction.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// (https://www.datadoghq.com/). Copyright 2022 Datadog, Inc.

#include "ip_extraction.h"
#include "compatibility.h"
#include "configuration.h"
#include "ddtrace.h"
#include "logging.h"
Expand Down Expand Up @@ -38,7 +39,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(extract_ip_addr, 0, 1, IS_STRING, 1)
ZEND_END_ARG_INFO()

static const zend_function_entry functions[] = {
ZEND_RAW_FENTRY(DD_TESTING_NS "extract_ip_addr", PHP_FN(datadog_appsec_testing_extract_ip_addr), extract_ip_addr, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "extract_ip_addr", PHP_FN(datadog_appsec_testing_extract_ip_addr), extract_ip_addr, 0, NULL, NULL)
PHP_FE_END
};
// clang-format on
Expand Down
5 changes: 3 additions & 2 deletions appsec/src/extension/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
#include "logging.h"
#include "attributes.h"
#include "compatibility.h"
#include "configuration.h"
#include "ddappsec.h"
#include "dddefs.h"
Expand Down Expand Up @@ -564,8 +565,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(fdclose, 0, 1, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

static const zend_function_entry functions[] = {
ZEND_RAW_FENTRY(DD_TESTING_NS "mlog", PHP_FN(datadog_appsec_testing_mlog), mlog, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "fdclose", PHP_FN(datadog_appsec_testing_fdclose), fdclose, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "mlog", PHP_FN(datadog_appsec_testing_mlog), mlog, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "fdclose", PHP_FN(datadog_appsec_testing_fdclose), fdclose, 0, NULL, NULL)
PHP_FE_END
};
// clang-format on
Expand Down
3 changes: 2 additions & 1 deletion appsec/src/extension/request_abort.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdlib.h>

#include "attributes.h"
#include "compatibility.h"
#include "configuration.h"
#include "ddappsec.h"
#include "dddefs.h"
Expand Down Expand Up @@ -564,7 +565,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(no_params_void_ret, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()

static const zend_function_entry functions[] = {
ZEND_RAW_FENTRY(DD_TESTING_NS "abort_static_page", PHP_FN(datadog_appsec_testing_abort_static_page), no_params_void_ret, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "abort_static_page", PHP_FN(datadog_appsec_testing_abort_static_page), no_params_void_ret, 0, NULL, NULL)
PHP_FE_END
};
// clang-format on
Expand Down
3 changes: 2 additions & 1 deletion appsec/src/extension/request_lifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "commands/config_sync.h"
#include "commands/request_init.h"
#include "commands/request_shutdown.h"
#include "compatibility.h"
#include "configuration.h"
#include "ddappsec.h"
#include "dddefs.h"
Expand Down Expand Up @@ -799,7 +800,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(dump_arginfo, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()

static const zend_function_entry functions[] = {
ZEND_RAW_FENTRY(DD_TESTING_NS "dump_req_lifecycle_state", PHP_FN(datadog_appsec_testing_dump_req_lifecycle_state), dump_arginfo, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "dump_req_lifecycle_state", PHP_FN(datadog_appsec_testing_dump_req_lifecycle_state), dump_arginfo, 0, NULL, NULL)
PHP_FE_END
};
// clang-format on
Expand Down
15 changes: 9 additions & 6 deletions appsec/src/extension/tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// This product includes software developed at Datadog
// (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
#include "tags.h"
#include "compatibility.h"
#include "ddappsec.h"
#include "ddtrace.h"
#include "ext/pcre/php_pcre.h"
Expand Down Expand Up @@ -878,6 +879,8 @@ bool match_regex(zend_string *pattern, zend_string *subject)
#if PHP_VERSION_ID < 70400
php_pcre_match_impl(
pce, ZSTR_VAL(subject), ZSTR_LEN(subject), &ret, NULL, 0, 0, 0, 0);
#elif PHP_VERSION_ID >= 80400
php_pcre_match_impl(pce, subject, &ret, NULL, 0, 0, 0);
#else
php_pcre_match_impl(pce, subject, &ret, NULL, 0, 0, 0, 0);
#endif
Expand Down Expand Up @@ -1314,16 +1317,16 @@ ZEND_ARG_INFO(0, metadata)
ZEND_END_ARG_INFO()

static const zend_function_entry functions[] = {
ZEND_RAW_FENTRY(DD_APPSEC_NS "track_user_signup_event", PHP_FN(datadog_appsec_track_user_signup_event), datadog_appsec_track_user_signup_event_arginfo, 0)
ZEND_RAW_FENTRY(DD_APPSEC_NS "track_user_login_success_event", PHP_FN(datadog_appsec_track_user_login_success_event), track_user_login_success_event_arginfo, 0)
ZEND_RAW_FENTRY(DD_APPSEC_NS "track_user_login_failure_event", PHP_FN(datadog_appsec_track_user_login_failure_event), track_user_login_failure_event_arginfo, 0)
ZEND_RAW_FENTRY(DD_APPSEC_NS "track_custom_event", PHP_FN(datadog_appsec_track_custom_event), track_custom_event_arginfo, 0)
ZEND_RAW_FENTRY(DD_APPSEC_NS "track_user_signup_event", PHP_FN(datadog_appsec_track_user_signup_event), datadog_appsec_track_user_signup_event_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_APPSEC_NS "track_user_login_success_event", PHP_FN(datadog_appsec_track_user_login_success_event), track_user_login_success_event_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_APPSEC_NS "track_user_login_failure_event", PHP_FN(datadog_appsec_track_user_login_failure_event), track_user_login_failure_event_arginfo, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_APPSEC_NS "track_custom_event", PHP_FN(datadog_appsec_track_custom_event), track_custom_event_arginfo, 0, NULL, NULL)
PHP_FE_END
};

static const zend_function_entry test_functions[] = {
ZEND_RAW_FENTRY(DD_TESTING_NS "add_all_ancillary_tags", PHP_FN(datadog_appsec_testing_add_all_ancillary_tags), add_ancillary_tags, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "add_basic_ancillary_tags", PHP_FN(datadog_appsec_testing_add_basic_ancillary_tags), add_ancillary_tags, 0)
ZEND_RAW_FENTRY(DD_TESTING_NS "add_all_ancillary_tags", PHP_FN(datadog_appsec_testing_add_all_ancillary_tags), add_ancillary_tags, 0, NULL, NULL)
ZEND_RAW_FENTRY(DD_TESTING_NS "add_basic_ancillary_tags", PHP_FN(datadog_appsec_testing_add_basic_ancillary_tags), add_ancillary_tags, 0, NULL, NULL)
PHP_FE_END
};
// clang-format on
Expand Down
2 changes: 1 addition & 1 deletion appsec/tests/integration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test {
}
tasks['test'].enabled(false)

ext.testMatrix = ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'].collectMany {
ext.testMatrix = ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3','8.4'].collectMany {
[[it, 'release'], [it, 'release-zts']]
}
ext.uuid = "id -u".execute().text.trim()
Expand Down

0 comments on commit 47dcd62

Please sign in to comment.