Skip to content

Commit 000f7f6

Browse files
bwoebirealFlowControl
authored andcommitted
Fix SpanLink::fromHeaders() crash with no or invalid propagated tags (#3025)
Signed-off-by: Bob Weinand <[email protected]>
1 parent f95ddcc commit 000f7f6

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Diff for: ext/ddtrace.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,9 @@ ZEND_METHOD(DDTrace_SpanLink, fromHeaders) {
870870

871871
zend_string *propagated_tags = ddtrace_format_propagated_tags(&result.propagated_tags, &result.meta_tags);
872872
zend_string *full_tracestate = ddtrace_format_tracestate(result.tracestate, 0, result.origin, result.priority_sampling, propagated_tags, &result.tracestate_unknown_dd_keys);
873-
zend_string_release(propagated_tags);
873+
if (propagated_tags) {
874+
zend_string_release(propagated_tags);
875+
}
874876
if (full_tracestate) {
875877
ZVAL_STR(&link->property_trace_state, full_tracestate);
876878
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Setting custom distributed header information with invalid propagated tags
3+
--ENV--
4+
HTTP_X_DATADOG_TRACE_ID=42
5+
HTTP_X_DATADOG_PARENT_ID=10
6+
HTTP_X_DATADOG_TAGS=_dd.p.custom_tag?!
7+
--FILE--
8+
<?php
9+
10+
print_r(DDTrace\SpanLink::fromHeaders([
11+
"traceparent" => "00-0000000000000000000000000000002a-0000000000000001-01",
12+
"tracestate" => "dd=foo:bar=baz",
13+
]));
14+
15+
?>
16+
--EXPECTF--
17+
DDTrace\SpanLink Object
18+
(
19+
[traceId] => 0000000000000000000000000000002a
20+
[spanId] => 0000000000000001
21+
[traceState] => dd=foo:bar=baz
22+
[attributes] => Array
23+
(
24+
[_dd.parent_id] => 0000000000000000
25+
)
26+
27+
)

0 commit comments

Comments
 (0)