linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libtraceeval: Fix timestamp when vals is NULL
@ 2023-10-11 22:23 Steven Rostedt
  0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2023-10-11 22:23 UTC (permalink / raw)
  To: Linux Trace Devel; +Cc: Ross Zwisler

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 --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;
-- 
2.42.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-11 22:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-11 22:23 [PATCH] libtraceeval: Fix timestamp when vals is NULL Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).