Skip to contentSkip to conversation

libtracefs/utest: Fix crashing of synth test when synths exist

PATCH New Steven Rostedt 1 participant 1 message May 30, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtracefs/utest: Fix crashing of synth test when synths exist

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

If a synthetic event already exists when running the synthetic event test, it does a SEGFAULT. This is because the sevents passed into test_synth_compare() is dependent on the devents size. If there's already a synthetic event, devents will be bigger than sevents, and the sevents will read out of bounds. Check for devents to be the same size as sevents before calling test_synth_compare()

---
 utest/tracefs-utest.c | 7 +++++++
 1 file changed, 7 insertions(+)
utest/tracefs-utest.c +7 -0
index 0f4075679ec4..3d88d927e320 100644
@@ -1047,6 +1047,12 @@ static void test_instance_synthetic(struct tracefs_instance *instance)
 
 	devents = get_dynevents_check(TRACEFS_DYNEVENT_SYNTH, sevents_count);
 	CU_TEST(devents != NULL);
+	if (!devents)
+		goto out;
+	CU_TEST(devents[sevents_count] == NULL);
+	if (devents[sevents_count])
+		goto out;
+
 	test_synth_compare(sevents, devents);
 	tracefs_dynevent_list_free(devents);
 
@@ -1057,6 +1063,7 @@ static void test_instance_synthetic(struct tracefs_instance *instance)
 
 	get_dynevents_check(TRACEFS_DYNEVENT_SYNTH, 0);
 
+ out:
 	for (i = 0; i < sevents_count; i++)
 		tracefs_synth_free(synth[i]);
 
Signature · 1 line
2.39.2