Skip to content

Commit

Permalink
Fix crash with double parent key in tracestate (#2837)
Browse files Browse the repository at this point in the history
Access of span_parent_key would be NULL on second 'p'.

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
  • Loading branch information
bwoebi committed Sep 5, 2024
1 parent 735db41 commit 37418fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions ext/distributed_tracing_headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,13 @@ static ddtrace_distributed_tracing_result ddtrace_read_distributed_tracing_ids_t
size_t valuelen = valueend - valuestart;

if (keylen == 1 && keystart[0] == 'p') {
zval zv;
ZVAL_STRINGL(&zv, valuestart, valuelen);
zend_hash_update(&result.meta_tags, span_parent_key, &zv);
zend_string_release(span_parent_key);
span_parent_key = NULL;
if (span_parent_key) {
zval zv;
ZVAL_STRINGL(&zv, valuestart, valuelen);
zend_hash_update(&result.meta_tags, span_parent_key, &zv);
zend_string_release(span_parent_key);
span_parent_key = NULL;
}
} else if (keylen == 1 && keystart[0] == 's') {
int extraced_priority = strtol(valuestart, NULL, 10);
if ((result.priority_sampling > 0) == (extraced_priority > 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DD_TRACE_PROPAGATION_STYLE=tracecontext

DDTrace\consume_distributed_tracing_headers([
"traceparent" => "00-0000000000000000000000000000002a-0000000000000001-01",
"tracestate" => "dd=p:00000000000000bb;s:1",
"tracestate" => "dd=p:00000000000000bb;p:00000000000000bb;s:1",
]);

$span = \DDTrace\start_span();
Expand Down

0 comments on commit 37418fd

Please sign in to comment.