diff mbox series

[3/3] libtracefs utest: Make a null string fatal if it is passed to strstr

Message ID 20210423035438.2221760-3-irogers@google.com (mailing list archive)
State Accepted
Commit 055ce1b76b6a60a2822d9199f0de31b016ab36d1
Headers show
Series [1/3] libtracefs utest: Silence string-plus-int warnings | expand

Commit Message

Ian Rogers April 23, 2021, 3:54 a.m. UTC
strstr will segv for a null string. If a string is passed to strstr and
is null there is no point segving, it is better to fail the earlier test
with a fatal and continue the rest of the suite. This allows the suite
to complete with an error rather than die.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 utest/tracefs-utest.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index a0d911b..e846dc4 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -452,21 +452,21 @@  static void test_instance_file(void)
 	ret = tracefs_instance_file_write(NULL, KPROB_EVTS, KPROBE_1);
 	CU_TEST(ret == strlen(KPROBE_1));
 	kprobes = tracefs_instance_file_read(NULL, KPROB_EVTS, &size);
-	CU_TEST(kprobes != NULL);
+	CU_TEST_FATAL(kprobes != NULL);
 	CU_TEST(strstr(kprobes, &KPROBE_1[2]) != NULL);
 	free(kprobes);
 
 	ret = tracefs_instance_file_append(NULL, KPROB_EVTS, KPROBE_2);
 	CU_TEST(ret == strlen(KPROBE_2));
 	kprobes = tracefs_instance_file_read(NULL, KPROB_EVTS, &size);
-	CU_TEST(kprobes != NULL);
+	CU_TEST_FATAL(kprobes != NULL);
 	CU_TEST(strstr(kprobes, &KPROBE_2[2]) != NULL);
 	free(kprobes);
 
 	ret = tracefs_instance_file_append(NULL, KPROB_EVTS, KPROBE_1_RM);
 	CU_TEST(ret == strlen(KPROBE_1_RM));
 	kprobes = tracefs_instance_file_read(NULL, KPROB_EVTS, &size);
-	CU_TEST(kprobes != NULL);
+	CU_TEST_FATAL(kprobes != NULL);
 	CU_TEST(strstr(kprobes, &KPROBE_1[2]) == NULL);
 	free(kprobes);
 
@@ -1026,7 +1026,7 @@  static void current_clock_check(struct tracefs_instance *instance, const char *c
 	char *str;
 
 	clocks = tracefs_instance_file_read(instance, TRACE_CLOCK, &size);
-	CU_TEST(clocks != NULL);
+	CU_TEST_FATAL(clocks != NULL);
 	CU_TEST(size > strlen(clock));
 	str = strstr(clocks, clock);
 	CU_TEST(str != NULL);
@@ -1041,7 +1041,7 @@  static void test_instance_get_clock(struct tracefs_instance *instance)
 	const char *clock;
 
 	clock = tracefs_get_clock(instance);
-	CU_TEST(clock != NULL);
+	CU_TEST_FATAL(clock != NULL);
 	current_clock_check(instance, clock);
 	free((char *)clock);
 }