diff mbox series

libtraceeval: Fix timestamp when vals is NULL

Message ID 20231011182351.098416bb@gandalf.local.home (mailing list archive)
State Under Review
Headers show
Series libtraceeval: Fix timestamp when vals is NULL | expand

Commit Message

Steven Rostedt Oct. 11, 2023, 10:23 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If traceeval_init() is passed NULL for vals, it can crash because he
teval->timestamp_idx is not updated and stays at zero. Then the check for
timestamp will iterate the NULL array of vals and crash.

Move the initialization of teval->timestamp_idx right after the teval is
allocated and do not depend on the val check to update it.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/histograms.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/histograms.c b/src/histograms.c
index 572f33eb3ac6..f77afc3a86a1 100644
--- a/src/histograms.c
+++ b/src/histograms.c
@@ -338,8 +338,6 @@  static int check_vals(struct traceeval *teval, struct traceeval_type *vals, int
 			vals[i].flags |= TRACEEVAL_FL_STAT;
 		vals[i].index = i;
 	}
-	if (!ts_found)
-		teval->timestamp_idx = -1;
 	return 0;
 }
 
@@ -402,6 +400,8 @@  struct traceeval *traceeval_init_data_size(struct traceeval_type *keys,
 		goto fail;
 	}
 
+	teval->timestamp_idx = -1;
+
 	ret = check_keys(keys, nr_keys);
 	if (ret < 0)
 		goto fail_release;