From: Ian Rogers <irogers@google.com>
To: Ian Rogers <irogers@google.com>,
Namhyung Kim <namhyung@kernel.org>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Chenyuan Mi <cymi20@fudan.edu.cn>,
linux-kernel@vger.kernel.org
Subject: [PATCH v1] lib subcmd: Avoid use-after-free when no commands are excluded
Date: Mon, 26 Jun 2023 15:22:13 -0700 [thread overview]
Message-ID: <20230626222213.366550-1-irogers@google.com> (raw)
The array shortening may be an unnecessary array copy. Before commit
657a3efee43a ("lib subcmd: Avoid memory leak in exclude_cmds") this
was benign, but afterwards this could lead to a segv.
Fixes: 657a3efee43a ("lib subcmd: Avoid memory leak in exclude_cmds")
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/lib/subcmd/help.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c
index 67a8d6b740ea..b59ca17e406d 100644
--- a/tools/lib/subcmd/help.c
+++ b/tools/lib/subcmd/help.c
@@ -77,10 +77,11 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)
ei++;
}
}
-
- while (ci < cmds->cnt) {
- zfree(&cmds->names[cj]);
- cmds->names[cj++] = cmds->names[ci++];
+ if (ci != cj) {
+ while (ci < cmds->cnt) {
+ zfree(&cmds->names[cj]);
+ cmds->names[cj++] = cmds->names[ci++];
+ }
}
for (ci = cj; ci < cmds->cnt; ci++)
zfree(&cmds->names[ci]);
--
2.41.0.162.gfafddb0af9-goog
next reply other threads:[~2023-06-26 22:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-26 22:22 Ian Rogers [this message]
2023-07-01 18:37 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230626222213.366550-1-irogers@google.com \
--to=irogers@google.com \
--cc=acme@redhat.com \
--cc=cymi20@fudan.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®