Skip to content

[Bug]: trailing ';' on generated tracestate #3322

@nicolas-boussuge-fintech

Description

Bug report

On ddtrace_format_tracestate, the code inject a separator ; without anything after when the zstr propagated_tags is valid but contains nothing.

if (propagated_tags) {
   if (str.s) {
       smart_str_appendc(&str, ';');
   }
   for (char *cur = ZSTR_VAL(propagated_tags), *end = cur + ZSTR_LEN(propagated_tags); cur < end; ++cur) {
      ...
   }
}

Like on the following condition, the code should check for both the validity & size of the variable:
if (propagated_tags && ZSTR_LEN(propagated_tags) > 0)

This might cause unexpected behaviours when a php service communicates with other languages (for example with a java application, cf unhandled case on W3C parser from dd-trace-java)

PHP version

7.4

Tracer or profiler version

1.10.0

Installed extensions

No response

Output of phpinfo()

No response

Upgrading from

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions