Skip to content

Commit f30f5e3

Browse files
morrisonleviclaude
andcommitted
test(config): regression test for buf-aliasing heap overflow in zai_config_find_and_set_value
When a DD_ env var is cached as a short persistent allocation and the corresponding OTEL fallback is invoked, the code (pre-fix) passes the aliased buf—still pointing at that tiny allocation—directly to the fallback. ddtrace_conf_otel_propagators then writes up to 30 bytes via memcpy, overflowing the allocation. The trigger: DD_TRACE_PROPAGATION_STYLE=, (a bare comma). The comma is non-empty so PHP's proc_open passes it to the child process normally. SET_LOWERCASE decode rejects all-separator input (zero set elements), leaving value.len == 0, which causes the fallback to fire with the aliased 2-byte buffer. Under ASAN this crashes the process during MINIT. The fix (commit 433ca60) allocates a fresh ZAI_ENV_MAX_BUFSIZ buffer for every fallback call so the aliased pointer is never used as the write destination. Note: DD_TRACE_PROPAGATION_STYLE= (empty string) cannot be used because PHP's proc_open silently drops env-array entries with empty-string values. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 433ca60 commit f30f5e3

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
OTEL_PROPAGATORS fallback uses correct buffer when DD_TRACE_PROPAGATION_STYLE fails to decode
3+
--DESCRIPTION--
4+
Regression test for a heap buffer overflow in zai_config_find_and_set_value.
5+
6+
When DD_TRACE_PROPAGATION_STYLE is set to a value that fails to decode (e.g. a
7+
bare comma, which is all-separators and produces an empty set), the sys env cache
8+
stores a small persistent allocation for the raw value. The decode failure leaves
9+
value.len == 0, so the OTEL fallback is triggered. On the unfixed code, buf.ptr
10+
is still aliased to that small allocation; ddtrace_conf_otel_propagators then
11+
writes up to 30 bytes into it via memcpy, causing a heap-buffer-overflow.
12+
13+
Under ASAN, the unfixed code crashes the process during MINIT before any PHP
14+
code runs; the test captures no output and fails. The fix uses a fresh 32 KB
15+
buffer for every fallback call, preventing the overflow.
16+
17+
Note: an empty string (DD_TRACE_PROPAGATION_STYLE=) cannot be used here because
18+
PHP's proc_open silently drops env-array entries with empty-string values. A bare
19+
comma (",") is non-empty so proc_open passes it, but SET_LOWERCASE decode rejects
20+
it (all-separator input produces zero set elements), triggering the same
21+
fallback+overflow path.
22+
--SKIPIF--
23+
<?php if (!extension_loaded('ddtrace')) die('skip: ddtrace extension required'); ?>
24+
--ENV--
25+
DD_TRACE_PROPAGATION_STYLE=,
26+
OTEL_PROPAGATORS=tracecontext,b3
27+
--FILE--
28+
<?php
29+
var_dump(ini_get("datadog.trace.propagation_style"));
30+
?>
31+
--EXPECT--
32+
string(29) "tracecontext,b3 single header"

0 commit comments

Comments
 (0)