perfetto icon indicating copy to clipboard operation
perfetto copied to clipboard

DynamicString can be constructed from a temporary std::string, leading to a dangling pointer

Open sashwinbalaji opened this issue 1 year ago • 1 comments

The DynamicString constructor can be called with a temporary std::string, which leads to a use-after-free.

For example, the following code compiles, but results in str.value pointing to freed memory after the temporary std::string is destroyed:

perfetto::DynamicString str(std::string("hello") + std::string("world"));
TRACE_EVENT_INSTANT("mycategory", str);

This leads to corrupted trace event data that can be hard to debug.

It would be best to make this a compile-time error.

(Copied from internal bug b/417982839 for public tracking)

sashwinbalaji avatar Nov 20 '25 23:11 sashwinbalaji

This was fixed by https://github.com/google/perfetto/pull/4272

LalitMaganti avatar Feb 16 '26 23:02 LalitMaganti