From 5c97e2daa9712d1fc3e1df186b25367b1e4cb8b1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 18 May 2022 11:49:34 -0400 Subject: [PATCH] Fix: ctf-writer: null dereference in bt_ctf_trace_common_add_stream_class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit gcc 12.1.0 reports that: In file included from object-pool.h:38, from clock-class.h:11, from trace.c:27: In function 'bt_ctf_object_set_parent', inlined from 'bt_ctf_object_set_parent' at object.h:102:6, inlined from 'bt_ctf_trace_common_add_stream_class' at trace.c:1227:3: object.h:123:26: warning: null pointer dereference [-Wnull-dereference] 123 | if (child->parent) { | ~~~~~^~~~~~~~ object.h:123:26: warning: null pointer dereference [-Wnull-dereference] This can indeed happen if bt_ctf_trace_common_add_stream_class is called with a nil stream class argument. A null check is added in the error path. Signed-off-by: Jérémie Galarneau Change-Id: I313966c1747c3929a46b98af71ba58f607d3c7df Reviewed-on: https://review.lttng.org/c/babeltrace/+/8084 --- src/ctf-writer/trace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ctf-writer/trace.c b/src/ctf-writer/trace.c index 58d6b3a2..c6c5f8bd 100644 --- a/src/ctf-writer/trace.c +++ b/src/ctf-writer/trace.c @@ -1224,7 +1224,9 @@ int bt_ctf_trace_common_add_stream_class(struct bt_ctf_trace_common *trace, end: if (ret) { - bt_ctf_object_set_parent(&stream_class->base, NULL); + if (stream_class) { + bt_ctf_object_set_parent(&stream_class->base, NULL); + } if (ec_validation_outputs) { for (i = 0; i < event_class_count; i++) { -- 2.34.1