[PATCH] trace-cmd list: Check if any functions were found

Steven Rostedt <[email protected]> Fri, 4 Apr 2025 15:49:49 -0400
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
From: "Steven Rostedt (Google)" <[email protected]>

The trace-cmd list operation on functions will crash if no functions were
found:

  $ trace-cmd list -f aueaeu
  Segmentation fault

The list returned is NULL but the code still loops over the list of found
functions. Do not loop if no function is found.

Fixes: 39acb4cc1 ("trace-cmd list: Use tracefs_filter_functions()")
Signed-off-by: Steven Rostedt (Google) <[email protected]>
---
 tracecmd/trace-list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c
index 8badd1f2..a441d136 100644
--- a/tracecmd/trace-list.c
+++ b/tracecmd/trace-list.c
@@ -476,7 +476,7 @@ static void show_functions(const char *funcre)
 
 	if (tracefs_filter_functions(funcre, NULL, &list) < 0)
 		die("Failed to read filte functions");
-	for (i = 0; list[i]; i++)
+	for (i = 0; list && list[i]; i++)
 		printf("%s\n", list[i]);
 	tracefs_list_free(list);
 }
-- 
2.47.2