linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf subcmd: Fix missing check for return value of malloc() in add_cmdname()
@ 2023-06-14 15:01 Chenyuan Mi
  2023-06-14 16:21 ` Ian Rogers
  0 siblings, 1 reply; 3+ messages in thread
From: Chenyuan Mi @ 2023-06-14 15:01 UTC (permalink / raw)
  To: acme; +Cc: irogers, namhyung, leo.yan, linux-kernel, Chenyuan Mi

The malloc() function may return NULL when it fails,
which may cause null pointer deference in add_cmdname(),
add Null check for return value of malloc().

Found by our static analysis tool.

Signed-off-by: Chenyuan Mi <cymi20@fudan.edu.cn>
---
 tools/lib/subcmd/help.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c
index bf02d62a3b2b..510a3eccb60f 100644
--- a/tools/lib/subcmd/help.c
+++ b/tools/lib/subcmd/help.c
@@ -16,6 +16,8 @@
 void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
 {
 	struct cmdname *ent = malloc(sizeof(*ent) + len + 1);
+	if (!ent)
+		return;
 
 	ent->len = len;
 	memcpy(ent->name, name, len);
-- 
2.17.1


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

* Re: [PATCH] perf subcmd: Fix missing check for return value of malloc() in add_cmdname()
  2023-06-14 15:01 [PATCH] perf subcmd: Fix missing check for return value of malloc() in add_cmdname() Chenyuan Mi
@ 2023-06-14 16:21 ` Ian Rogers
  2023-06-21 17:24   ` Namhyung Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2023-06-14 16:21 UTC (permalink / raw)
  To: Chenyuan Mi; +Cc: acme, namhyung, leo.yan, linux-kernel

On Wed, Jun 14, 2023 at 8:01 AM Chenyuan Mi <cymi20@fudan.edu.cn> wrote:
>
> The malloc() function may return NULL when it fails,
> which may cause null pointer deference in add_cmdname(),
> add Null check for return value of malloc().
>
> Found by our static analysis tool.
>
> Signed-off-by: Chenyuan Mi <cymi20@fudan.edu.cn>

Acked-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/lib/subcmd/help.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c
> index bf02d62a3b2b..510a3eccb60f 100644
> --- a/tools/lib/subcmd/help.c
> +++ b/tools/lib/subcmd/help.c
> @@ -16,6 +16,8 @@
>  void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
>  {
>         struct cmdname *ent = malloc(sizeof(*ent) + len + 1);
> +       if (!ent)
> +               return;
>
>         ent->len = len;
>         memcpy(ent->name, name, len);
> --
> 2.17.1
>

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

* Re: [PATCH] perf subcmd: Fix missing check for return value of malloc() in add_cmdname()
  2023-06-14 16:21 ` Ian Rogers
@ 2023-06-21 17:24   ` Namhyung Kim
  0 siblings, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2023-06-21 17:24 UTC (permalink / raw)
  To: Ian Rogers; +Cc: Chenyuan Mi, acme, leo.yan, linux-kernel

On Wed, Jun 14, 2023 at 9:21 AM Ian Rogers <irogers@google.com> wrote:
>
> On Wed, Jun 14, 2023 at 8:01 AM Chenyuan Mi <cymi20@fudan.edu.cn> wrote:
> >
> > The malloc() function may return NULL when it fails,
> > which may cause null pointer deference in add_cmdname(),
> > add Null check for return value of malloc().
> >
> > Found by our static analysis tool.
> >
> > Signed-off-by: Chenyuan Mi <cymi20@fudan.edu.cn>
>
> Acked-by: Ian Rogers <irogers@google.com>

Applied to perf-tools-next, thanks!

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

end of thread, other threads:[~2023-06-21 17:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-14 15:01 [PATCH] perf subcmd: Fix missing check for return value of malloc() in add_cmdname() Chenyuan Mi
2023-06-14 16:21 ` Ian Rogers
2023-06-21 17:24   ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).