heap-use-after-free with BatchLogRecordProcessor #3135
Labels
bug
Something isn't working
triage/accepted
Indicates an issue or PR is ready to be actively worked on.
Describe your environment
OpenTelemetry v1.17.0
Steps to reproduce
Sample code: https://github.com/sjinks/otel-heap-use-after-free
Sample run: https://github.com/sjinks/otel-heap-use-after-free/actions/runs/11758831588/job/32757617053
What is the expected behavior?
There should be no errors.
What is the actual behavior?
The application crashed because of the heap-use-after-free-error
Additional context
The bug happens when the
catch
block is left before theBatchLogRecordProcessor
processes the data.My understanding is that the log message is stored
ReadWriteLogRecord::body_
which isopentelemetry::common::AttributeValue
, anostd::variant
holding aconst char*
value. Whene
goes out of the scope and gets destructed, the memory pointed to bye.what()
is also freed. However, becauseAttributeValue
does not own the data, it is left with a dangling pointer.The fix will probably be to replace
AttributeValue
withOwnedAttributeValue
(this will affectbody_
andattributes_map_
).Refs:
The text was updated successfully, but these errors were encountered: