Skip to content

Commit a5edf35

Browse files
dumpstack1024namhyung
authored andcommitted
perf subcmd: avoid crash in exclude_cmds when excludes is empty
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 <[email protected]> Reported-by: Guilherme Amadio <[email protected]> Reviewed-by: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent ca81e74 commit a5edf35

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tools/lib/subcmd/help.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)
7575
size_t ci, cj, ei;
7676
int cmp;
7777

78+
if (!excludes->cnt)
79+
return;
80+
7881
ci = cj = ei = 0;
7982
while (ci < cmds->cnt && ei < excludes->cnt) {
8083
cmp = strcmp(cmds->names[ci]->name, excludes->names[ei]->name);

0 commit comments

Comments
 (0)