Skip to content

Commit

Permalink
Fix phpt tests on version 7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
estringana committed Aug 12, 2024
1 parent 2320656 commit 0304b3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 10 additions & 4 deletions appsec/src/extension/msgpack_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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!
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions appsec/tests/extension/generate_backtrace_07.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DD_TRACE_GENERATE_ROOT_SPAN=0
extension=ddtrace.so
--FILE--
<?php
namespace Some\NameSpace {
namespace Some\Package {
use function datadog\appsec\testing\generate_backtrace;

class Foo {
Expand All @@ -32,7 +32,7 @@ namespace {
DDTrace\start_span();
$root = DDTrace\active_span();

$class = new Some\NameSpace\Foo();
$class = new Some\Package\Foo();
$class->one("foo01");
}
?>
Expand All @@ -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"]=>
Expand All @@ -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"]=>
Expand All @@ -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"]=>
Expand Down

0 comments on commit 0304b3e

Please sign in to comment.