diff mbox series

trace-cmd: Have tracecmd_write_guest_time_shift() handle NULL tsync

Message ID 20220707191621.77deba71@gandalf.local.home (mailing list archive)
State Accepted
Commit 528ff5f6c798d49015bbe500a555d971831371a0
Headers show
Series trace-cmd: Have tracecmd_write_guest_time_shift() handle NULL tsync | expand

Commit Message

Steven Rostedt July 7, 2022, 11:16 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If the clock_context_init() fails, the ctx->instance->tsync will be NULL,
but it may be used in calling tracecmd_write_guest_time_shift(). This will
cause a SEGFAULT as that function expects it to be non NULL.

Test for tsync not NULL and return -1 if it is.

More should be done to warn when this happens, but for now prevent the
SEGFAULT. This makes the code more robust.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-timesync.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
index bc6430983a96..75c27babfe43 100644
--- a/lib/trace-cmd/trace-timesync.c
+++ b/lib/trace-cmd/trace-timesync.c
@@ -835,7 +835,7 @@  int tracecmd_write_guest_time_shift(struct tracecmd_output *handle,
 	int i, j;
 	int ret = -1;
 
-	if (!tsync->vcpu_count)
+	if (!tsync || !tsync->vcpu_count)
 		return -1;
 	vcount = 3 + (5 * tsync->vcpu_count);
 	vector = calloc(vcount, sizeof(struct iovec));