Fix: ctf-writer: null dereference in bt_ctf_trace_common_add_stream_class
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 18 May 2022 15:49:34 +0000 (11:49 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 12 Jul 2023 18:55:17 +0000 (14:55 -0400)
Cherry-pick note: I (Simon) see this error when building on the CI's ppc
machine, although I don't see it on the CI job.

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 <jeremie.galarneau@efficios.com>
Change-Id: I313966c1747c3929a46b98af71ba58f607d3c7df
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8084
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9566
Tested-by: jenkins <jenkins@lttng.org>
src/ctf-writer/trace.c

index 804af24dc1819192e9451876f8cec190c828da63..482d81d84dcb6776cb37dd3318095f0c9c3ca9c6 100644 (file)
@@ -1240,7 +1240,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++) {
This page took 0.02573 seconds and 4 git commands to generate.