linux/tools/lib/subcmd
Sri Jayaramappa b6ee9b6e20 libsubcmd: Fix null intersection case in exclude_cmds()
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: 1fdf938168 ("perf tools: Fix use-after-free in help_unknown_cmd()")
Reviewed-by: Guilherme Amadio <amadio@gentoo.org>
Signed-off-by: Sri Jayaramappa <sjayaram@akamai.com>
Tested-by: Guilherme Amadio <amadio@gentoo.org>
Tested-by: Ian Rogers <irogers@google.com>
Cc: Joshua Hunt <johunt@akamai.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20251202213632.2873731-1-sjayaram@akamai.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-01-13 16:45:43 -03:00
..
Build
Makefile tools: Drop nonsensical -O6 2024-09-11 13:08:36 -03:00
exec-cmd.c
exec-cmd.h
help.c libsubcmd: Fix null intersection case in exclude_cmds() 2026-01-13 16:45:43 -03:00
help.h
pager.c
pager.h
parse-options.c libsubcmd: Silence compiler warning 2024-10-23 14:38:34 -07:00
parse-options.h
run-command.c tools subcmd: Tighten the filename size in check_if_command_finished 2025-07-22 18:17:53 -07:00
run-command.h
sigchain.c
sigchain.h
subcmd-config.c
subcmd-config.h
subcmd-util.h libsubcmd: Move va_end() before exit 2024-11-13 16:27:35 -03:00