From 83e6358a4e254a70bf965f67f56c9277e087f0ca Mon Sep 17 00:00:00 2001 From: Alejandro Estringana Ruiz Date: Mon, 12 Aug 2024 11:34:22 +0200 Subject: [PATCH] Fix phpt tests on version 7.x --- appsec/src/extension/msgpack_helpers.c | 14 ++++++++++---- appsec/tests/extension/generate_backtrace_07.phpt | 10 +++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/appsec/src/extension/msgpack_helpers.c b/appsec/src/extension/msgpack_helpers.c index 02ad8c43fd7..93929a12c5d 100644 --- a/appsec/src/extension/msgpack_helpers.c +++ b/appsec/src/extension/msgpack_helpers.c @@ -12,6 +12,8 @@ #include "php_helpers.h" #include "php_objects.h" +static const int MAX_DEPTH = 32; + static void _mpack_write_zval(mpack_writer_t *nonnull w, zval *nonnull zv); void dd_mpack_write_nullable_cstr( @@ -264,9 +266,11 @@ static void _iovec_writer_teardown(mpack_writer_t *w) w->context = NULL; } -static void parse_element(mpack_reader_t *reader, int depth, zval *output) +// NOLINTNEXTLINE(misc-no-recursion) +static void parse_element( + mpack_reader_t *nonnull reader, int depth, zval *nonnull output) { - if (depth >= 32) { // critical check! + if (depth >= MAX_DEPTH) { // critical check! mpack_reader_flag_error(reader, mpack_error_too_big); mlog(dd_log_error, "decode_msgpack error: msgpack object too big"); return; @@ -319,7 +323,8 @@ static void parse_element(mpack_reader_t *reader, int depth, zval *output) uint32_t count = mpack_tag_map_count(&tag); array_init(output); while (count-- > 0) { - zval key, value; + zval key; + zval value; parse_element(reader, depth + 1, &key); parse_element(reader, depth + 1, &value); if (mpack_reader_error(reader) != mpack_ok) { // critical check! @@ -340,7 +345,8 @@ static void parse_element(mpack_reader_t *reader, int depth, zval *output) } } -static bool parse_messagepack(const char *data, size_t length, zval *output) +static bool parse_messagepack( + const char *nonnull data, size_t length, zval *nonnull output) { mpack_reader_t reader; mpack_reader_init_data(&reader, data, length); diff --git a/appsec/tests/extension/generate_backtrace_07.phpt b/appsec/tests/extension/generate_backtrace_07.phpt index 44f85303024..307d01327d6 100644 --- a/appsec/tests/extension/generate_backtrace_07.phpt +++ b/appsec/tests/extension/generate_backtrace_07.phpt @@ -6,7 +6,7 @@ DD_TRACE_GENERATE_ROOT_SPAN=0 extension=ddtrace.so --FILE-- one("foo01"); } ?> @@ -49,7 +49,7 @@ array(3) { ["line"]=> int(12) ["function"]=> - string(25) "Some\NameSpace\Foo::three" + string(23) "Some\Package\Foo::three" ["file"]=> string(25) "generate_backtrace_07.php" ["id"]=> @@ -60,7 +60,7 @@ array(3) { ["line"]=> int(17) ["function"]=> - string(23) "Some\NameSpace\Foo::two" + string(21) "Some\Package\Foo::two" ["file"]=> string(25) "generate_backtrace_07.php" ["id"]=> @@ -71,7 +71,7 @@ array(3) { ["line"]=> int(29) ["function"]=> - string(23) "Some\NameSpace\Foo::one" + string(21) "Some\Package\Foo::one" ["file"]=> string(25) "generate_backtrace_07.php" ["id"]=>