public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libsubcmd: Fix null intersection case in exclude_cmds()
@ 2025-12-02 21:36 Sri Jayaramappa
  2025-12-07 22:16 ` Ian Rogers
  0 siblings, 1 reply; 7+ messages in thread
From: Sri Jayaramappa @ 2025-12-02 21:36 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers, Namhyung Kim,
	Peter Zijlstra
  Cc: linux-perf-users, linux-kernel, Joshua Hunt, Sri Jayaramappa

When there is no exclusion occurring from the cmds list - for example -
cmds contains ["read-vdso32"] and excludes contains ["archive"] - the
main loop completes with ci == cj == 0. In the original code the loop
processing the remaining elements in the list was conditional:

    if (ci != cj) { ...}

So we end up in the assertion loop since ci < cmds->cnt and we
incorrectly try to assert the list elements to be NULL and fail with
the following error

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

Fix this by moving the if (ci != cj) check inside of a broader loop.
If ci != cj, left shift the list elements, as before, and then
unconditionally advance the ci and cj indicies which also covers the
ci == cj case.

Fixes: 1fdf938168c4d26f ("perf tools: Fix use-after-free in help_unknown_cmd()")

Signed-off-by: Sri Jayaramappa <sjayaram@akamai.com>
---
 tools/lib/subcmd/help.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c
index ddaeb4eb3e24..db94aa685b73 100644
--- a/tools/lib/subcmd/help.c
+++ b/tools/lib/subcmd/help.c
@@ -97,11 +97,13 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)
 			ei++;
 		}
 	}
-	if (ci != cj) {
-		while (ci < cmds->cnt) {
-			cmds->names[cj++] = cmds->names[ci];
-			cmds->names[ci++] = NULL;
+	while (ci < cmds->cnt) {
+		if (ci != cj) {
+			cmds->names[cj] = cmds->names[ci];
+			cmds->names[ci] = NULL;
 		}
+		ci++;
+		cj++;
 	}
 	for (ci = cj; ci < cmds->cnt; ci++)
 		assert(cmds->names[ci] == NULL);
-- 
2.34.1


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

end of thread, other threads:[~2026-01-13 19:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-02 21:36 [PATCH] libsubcmd: Fix null intersection case in exclude_cmds() Sri Jayaramappa
2025-12-07 22:16 ` Ian Rogers
2025-12-08 17:26   ` Ian Rogers
2026-01-13 19:49     ` Arnaldo Carvalho de Melo
2025-12-10  2:00   ` Sri Jayaramappa
2025-12-10 18:38     ` Ian Rogers
2025-12-11  1:15       ` Jayaramappa, Srilakshmi

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