Skip to content

core: harden lifecycle and random ID handling#87

Draft
edsiper wants to merge 1 commit into
masterfrom
agent/harden-lifecycle-randomness
Draft

core: harden lifecycle and random ID handling#87
edsiper wants to merge 1 commit into
masterfrom
agent/harden-lifecycle-randomness

Conversation

@edsiper

@edsiper edsiper commented Jul 11, 2026

Copy link
Copy Markdown
Member

Summary

  • unlink resource spans safely during destruction while remaining compatible with Fluent Bit's sampling processor, which historically unlinks them first
  • make ID, trace state, schema URL, status, link, and attribute replacement operations safe when allocation fails or values are reused
  • make random ID generation consume complete entropy reads, retry interruptions, and remove the predictable PRNG fallback
  • fix the CMake getrandom() capability probe and add lifecycle/random-ID regression coverage

Root cause and impact

ctr_resource_span_destroy() freed resource spans without unlinking them from the owning trace context. Direct destruction could therefore leave a dangling list node that was traversed again by ctr_destroy(), resulting in a use-after-free or double-free.

The destructor now unlinks nodes that are still attached. It also detects an already-unlinked node, preserving the existing Fluent Bit trace sampling processor sequence of manually unlinking before destruction.

Several replacement setters also released their existing allocation before creating the replacement. Allocation failure could leave dangling pointers and trigger later double-frees. Replacements are now allocated before the old value is released.

Random generation previously accepted short reads and could leave zero-filled bytes in generated IDs. The Unix implementations now retry interrupted operations and require the requested buffer to be filled completely.

Validation

  • ASAN_OPTIONS=detect_leaks=1 ctest --test-dir build --output-on-failure
  • GCC AddressSanitizer and UndefinedBehaviorSanitizer build: 4/4 tests passed
  • GCC -fanalyzer build completed
  • Clang 18 release build: 4/4 tests passed
  • ctraces-simple-c-api example completed successfully
  • git diff --check

The resource-span regression test covers both direct destruction and Fluent Bit's existing manual-unlink sampling pattern.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant