Skip to content

Commit b4cf9f1

Browse files
committed
fix build
1 parent 2c022b2 commit b4cf9f1

12 files changed

Lines changed: 57 additions & 37 deletions

.gitlab/build-appsec.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ suffix="${1:-}"
1313
echo "Build nts extension"
1414
switch-php "${PHP_VERSION}"
1515
mkdir -p appsec/build ; cd appsec/build
16-
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDD_APPSEC_TESTING=OFF -DDD_APPSEC_EXTENSION_STATIC_LIBSTDCXX=ON
16+
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDD_APPSEC_BUILD_HELPER=OFF -DDD_APPSEC_TESTING=OFF -DDD_APPSEC_EXTENSION_STATIC_LIBSTDCXX=ON
1717
make -j $MAKE_JOBS
1818
cp -v ddappsec.so "../../appsec_$(uname -m)/ddappsec-$PHP_API${suffix}.so"
1919
cd "../../"
2020

2121
echo "Build zts extension"
2222
switch-php "${PHP_VERSION}-zts"
2323
mkdir -p appsec/build-zts ; cd appsec/build-zts
24-
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDD_APPSEC_TESTING=OFF -DDD_APPSEC_EXTENSION_STATIC_LIBSTDCXX=ON
24+
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDD_APPSEC_BUILD_HELPER=OFF -DDD_APPSEC_TESTING=OFF -DDD_APPSEC_EXTENSION_STATIC_LIBSTDCXX=ON
2525
make -j $MAKE_JOBS
2626
cp -v ddappsec.so "../../appsec_$(uname -m)/ddappsec-$PHP_API${suffix}-zts.so"
2727
cd "../../"

appsec/src/extension/compatibility.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,23 @@
88
#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 },
99
#endif
1010

11+
#if PHP_VERSION_ID < 80000
12+
// ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE was added in PHP 8.0.
13+
// For PHP 7.x, fall back to ZEND_ARG_TYPE_INFO (the default_value hint is not
14+
// stored in PHP 7 internal arginfo structs).
15+
#define ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, type, allow_null, default_value) \
16+
ZEND_ARG_TYPE_INFO(pass_by_ref, name, type, allow_null)
17+
#endif
18+
19+
#if PHP_VERSION_ID < 70100
20+
// PHP 7.0's ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX takes a 6th class_name
21+
// argument removed in 7.1. Our generated arginfo uses the 5-argument form.
22+
// Redefine to accept 5 args and pass NULL as the class name (correct for all
23+
// primitive return types we expose).
24+
#undef ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX
25+
#define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
26+
static const zend_internal_arg_info name[] = { \
27+
{ (const char *)(zend_uintptr_t)(required_num_args), NULL, (zend_uchar)(type), return_reference, allow_null, 0 },
28+
#endif
29+
1130
#endif // DD_COMPATIBILITY_H

appsec/src/extension/ddappsec.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "logging.h"
3636
#include "msgpack_helpers.h"
3737
#include "network.h"
38-
#include "php_compat.h"
38+
#include "php_compat.h" // NOLINT (must come before ddappsec_arginfo.h)
3939
#include "php_objects.h"
4040
#include "request_abort.h"
4141
#include "request_lifecycle.h"
@@ -185,15 +185,15 @@ static PHP_GINIT_FUNCTION(ddappsec)
185185
// though I guess we could do it maybe on MSHUTDOWN or GSHUTDOWN if we
186186
// detected it was running for the main thread globals there.
187187
if (!tsrm_is_main_thread()) {
188-
# if defined(__linux__)
188+
# if defined(__linux__)
189189
extern void *__dso_handle;
190190
extern int __cxa_thread_atexit_impl(
191191
void (*func)(void *), void *arg, void *dso_handle);
192192
__cxa_thread_atexit_impl(_tshutdown_handler, NULL, __dso_handle);
193-
# elif defined(__APPLE__)
193+
# elif defined(__APPLE__)
194194
extern void _tlv_atexit(void (*termFunc)(void *), void *objAddr);
195195
_tlv_atexit(_tshutdown_handler, NULL);
196-
# endif
196+
# endif
197197
}
198198
#endif
199199
}
@@ -242,7 +242,6 @@ static PHP_GSHUTDOWN_FUNCTION(ddappsec)
242242
memset(ddappsec_globals, '\0', sizeof(*ddappsec_globals)); // NOLINT
243243
}
244244

245-
246245
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
247246
static PHP_MINIT_FUNCTION(ddappsec)
248247
{

appsec/src/extension/ddtrace.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ static zend_string *(*nullable _ddtrace_guess_endpoint_from_url)(
7676
const char *nonnull url, size_t url_len);
7777
static ddog_AppsecCResponse (*nullable _ddog_sidecar_send_appsec_message)(
7878
ddog_SidecarTransport *nonnull *nonnull transport,
79-
ddog_CharSlice session_id, uint64_t client_id,
80-
ddog_CharSlice data);
79+
ddog_CharSlice session_id, uint64_t client_id, ddog_CharSlice data);
8180
static void (*nullable _ddog_sidecar_appsec_response_drop)(
8281
ddog_AppsecCResponse response);
8382

@@ -395,9 +394,8 @@ uint64_t dd_trace_get_sidecar_queue_id(void)
395394
}
396395

397396
#ifdef ZTS
398-
ddog_AppsecCResponse dd_trace_send_appsec_message(
399-
uint64_t client_id, void *nullable tsrm_ls,
400-
const uint8_t *nonnull request, size_t request_len)
397+
ddog_AppsecCResponse dd_trace_send_appsec_message(uint64_t client_id,
398+
void *nullable tsrm_ls, const uint8_t *nonnull request, size_t request_len)
401399
#else
402400
ddog_AppsecCResponse dd_trace_send_appsec_message(
403401
uint64_t client_id, const uint8_t *nonnull request, size_t request_len)
@@ -422,7 +420,8 @@ ddog_AppsecCResponse dd_trace_send_appsec_message(
422420
}
423421

424422
#ifdef ZTS
425-
ddog_SidecarTransport *nullable sidecar = *_ddtrace_get_sidecar_transport(tsrm_ls);
423+
ddog_SidecarTransport *nullable sidecar =
424+
*_ddtrace_get_sidecar_transport(tsrm_ls);
426425
#else
427426
ddog_SidecarTransport *nullable sidecar = *_ddtrace_get_sidecar_transport();
428427
#endif

appsec/src/extension/helper_process.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ __attribute__((visibility("default"))) bool dd_appsec_maybe_enable_helper(
216216
return true;
217217
}
218218

219-
void dd_helper_close_conn(bool goodbye, const char *nullable error, size_t error_len)
219+
void dd_helper_close_conn(
220+
bool goodbye, const char *nullable error, size_t error_len)
220221
{
221222
if (!dd_conn_connected(&DDAPPSEC_G(conn))) {
222223
if (!error) {

appsec/src/extension/network.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ dd_result dd_conn_roundtripv(dd_conn *nonnull conn, zend_llist *nonnull iovecs,
7979
}
8080

8181
#ifdef ZTS
82-
ddog_AppsecCResponse response = dd_trace_send_appsec_message(
83-
conn->client_id, DDAPPSEC_G(ts_ls_cache),
84-
(const uint8_t *)req, total_len);
82+
ddog_AppsecCResponse response =
83+
dd_trace_send_appsec_message(conn->client_id, DDAPPSEC_G(ts_ls_cache),
84+
(const uint8_t *)req, total_len);
8585
#else
8686
ddog_AppsecCResponse response = dd_trace_send_appsec_message(
8787
conn->client_id, (const uint8_t *)req, total_len);
@@ -91,9 +91,10 @@ dd_result dd_conn_roundtripv(dd_conn *nonnull conn, zend_llist *nonnull iovecs,
9191
dd_result ret;
9292

9393
if (response.disconnect) {
94-
mlog(dd_log_warning, "Helper has responded with an error indicating we "
95-
"need to redo client_init (abandon client id %"
96-
PRIu64 ")", conn->client_id);
94+
mlog(dd_log_warning,
95+
"Helper has responded with an error indicating we "
96+
"need to redo client_init (abandon client id %" PRIu64 ")",
97+
conn->client_id);
9798
// in this case, the helper indicated it's abandoned the client already,
9899
// so we can't send the goodbye
99100
ret = dd_helper_fatal;

appsec/src/extension/request_lifecycle.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,18 @@ retry:;
252252

253253
zend_array *spec = NULL;
254254
if (res == dd_helper_say_goobye) {
255-
mlog_g(dd_log_info,
256-
"request_init/config_sync failed with dd_helper_say_goobye; closing "
257-
"connection to helper");
258-
dd_helper_close_conn(true, LSTRARG(
259-
"request_init/config_sync failed with dd_helper_say_goobye"));
255+
mlog_g(dd_log_info, "request_init/config_sync failed with "
256+
"dd_helper_say_goobye; closing "
257+
"connection to helper");
258+
dd_helper_close_conn(true,
259+
LSTRARG(
260+
"request_init/config_sync failed with dd_helper_say_goobye"));
260261
} else if (res == dd_helper_fatal) {
261262
mlog_g(dd_log_info,
262263
"request_init/config_sync failed with dd_helper_fatal; closing "
263264
"connection to helper");
264-
dd_helper_close_conn(false, LSTRARG(
265-
"request_init/config_sync failed with dd_helper_fatal"));
265+
dd_helper_close_conn(false,
266+
LSTRARG("request_init/config_sync failed with dd_helper_fatal"));
266267
} else if (res == dd_should_block || res == dd_should_redirect) {
267268
spec = dd_req_lifecycle_abort(
268269
REQUEST_STAGE_REQUEST_BEGIN, res, &req_info.req_info.block_params);
@@ -368,8 +369,8 @@ static void _do_request_finish_php(bool ignore_verdict)
368369
"request_shutdown failed with dd_helper_say_goobye or "
369370
"dd_helper_fatal; closing connection to helper");
370371
bool goodbye = res == dd_helper_say_goobye;
371-
dd_helper_close_conn(goodbye,
372-
LSTRARG("request_shutdown failed with dd_helper_..."));
372+
dd_helper_close_conn(
373+
goodbye, LSTRARG("request_shutdown failed with dd_helper_..."));
373374
} else if (res == dd_should_block || res == dd_should_redirect) {
374375
verdict = ignore_verdict ? dd_success : res;
375376
} else if (res) {
@@ -420,8 +421,8 @@ static zend_array *_do_request_finish_user_req(bool ignore_verdict,
420421
"request_shutdown failed with dd_helper_say_goobye or "
421422
"dd_helper_fatal; closing connection to helper");
422423
bool goodbye = res == dd_helper_say_goobye;
423-
dd_helper_close_conn(goodbye,
424-
LSTRARG("request_shutdown failed with dd_helper_..."));
424+
dd_helper_close_conn(
425+
goodbye, LSTRARG("request_shutdown failed with dd_helper_..."));
425426
} else if (res == dd_should_block || res == dd_should_redirect) {
426427
verdict = ignore_verdict ? dd_success : res;
427428
} else if (res) {

appsec/tests/extension/client_init_bad_msg.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $helper = Helper::createRun([
1717
sleep(1);
1818
var_dump(rinit());
1919

20-
match_log('/Unexpected client_init response: mpack_error_type/');
20+
match_log('/Helper has not responded with a valid client_id/');
2121
match_log('/Response message for client_init does not have the expected form/');
2222
match_log('/Initial exchange with helper failed; abandoning the connection/');
2323

@@ -29,7 +29,7 @@ match_log('/Contents of message \\(base64 encoded\\): /');
2929
?>
3030
--EXPECTF--
3131
bool(true)
32-
found message in log matching /Unexpected client_init response: mpack_error_type/
32+
found message in log matching /Helper has not responded with a valid client_id/
3333
found message in log matching /Response message for client_init does not have the expected form/
3434
found message in log matching /Initial exchange with helper failed; abandoning the connection/
3535
array(2) {

appsec/tests/extension/client_init_fail.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $obj = new ArrayObject();
1010
$helper = Helper::createRun(
1111
[
1212
response_list(
13-
response_client_init(['not-ok', phpversion('ddappsec'), 0, ['such and such error occurred'], $obj, $obj, null])
13+
response_client_init(['not-ok', phpversion('ddappsec'), 1, ['such and such error occurred'], $obj, $obj, null])
1414
)
1515
]);
1616

appsec/tests/extension/client_init_record_span_tags.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ include __DIR__ . '/inc/mock_helper.php';
3030

3131
$helper = Helper::createRun([
3232
response_list(
33-
response_client_init(['ok', phpversion('ddappsec'), 0, [],
33+
response_client_init(['ok', phpversion('ddappsec'), 1, [],
3434
["meta_1" => "value_1", "meta_2" => "value_2"],
3535
["metric_1" => 2.0, "metric_2" => 10.0], null])
3636
),

0 commit comments

Comments
 (0)