public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC] perf subcmd: avoid crash in exclude_cmds when excludes is empty
@ 2025-09-10  8:16 hupu
  2025-09-10  8:27 ` hupu
  0 siblings, 1 reply; 4+ messages in thread
From: hupu @ 2025-09-10  8:16 UTC (permalink / raw)
  To: irogers, namhyung, linux-kernel; +Cc: hupu.gm

When cross-compiling the perf tool for ARM64, `perf help` may crash
with the following assertion failure:

  help.c:122: exclude_cmds: Assertion `cmds->names[ci] == NULL' failed.

This happens when the perf binary is not named exactly "perf" or when
multiple "perf-*" binaries exist in the same directory. In such cases,
the `excludes` command list can be empty, which leads to the final
assertion in exclude_cmds() being triggered.

Add a simple guard at the beginning of exclude_cmds() to return early
if excludes->cnt is zero, preventing the crash.

Signed-off-by: hupu <hupu.gm@gmail.com>
---
 tools/lib/subcmd/help.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c
index 9ef569492560..ddaeb4eb3e24 100644
--- a/tools/lib/subcmd/help.c
+++ b/tools/lib/subcmd/help.c
@@ -75,6 +75,9 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)
 	size_t ci, cj, ei;
 	int cmp;
 
+	if (!excludes->cnt)
+		return;
+
 	ci = cj = ei = 0;
 	while (ci < cmds->cnt && ei < excludes->cnt) {
 		cmp = strcmp(cmds->names[ci]->name, excludes->names[ei]->name);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-12  7:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-10  8:16 [RFC] perf subcmd: avoid crash in exclude_cmds when excludes is empty hupu
2025-09-10  8:27 ` hupu
2025-09-11 21:09   ` Namhyung Kim
2025-09-12  7:39     ` hupu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox