From 9ea90bc6b28163fd13ee6caf93864f1e9eed8d77 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 22 Nov 2024 11:02:11 +0100 Subject: [PATCH] common: Fix a potential cycle in the trace structure It turns out that under some circumstances we end up clearing the pointee of `current` but not the pointer. Thus when we select the next slot we can end up reusing the same slot, making it its own parent. We forcefull break these cycles by enforcing that `current` should never be returned and be set as its own parent. Changelog-None --- common/trace.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/trace.c b/common/trace.c index 4ea851310544..6ea624535b69 100644 --- a/common/trace.c +++ b/common/trace.c @@ -179,6 +179,13 @@ static struct span *trace_span_slot(void) * concurrent spans. */ assert(s); assert(s->parent == NULL); + + /* Be extra careful not to create cycles. If we return the + * position that is pointed at by current then we can only + * stub the trace by removing the parent link here. */ + if (s == current) + current = NULL; + return s; }