Skip to contentSkip to conversation

libtraceeval: Fix timestamp when vals is NULL

PATCH New Steven Rostedt 1 participant 1 message Oct 11, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtraceeval: Fix timestamp when vals is NULL

From: "Steven Rostedt (Google)" <[email protected]>

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.

---
 src/histograms.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/histograms.c +2 -2
index 572f33eb3ac6..f77afc3a86a1 100644
@@ -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;
Signature · 1 line
2.42.0