mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 05:02:12 +00:00
perf subcmd: Fix missing check for return value of malloc() in add_cmdname()
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> Cc: Leo Yan <leo.yan@linaro.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: linux-kernel@vger.kernel.org Link: https://lore.kernel.org/r/20230614150118.115208-1-cymi20@fudan.edu.cn Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
parent
240de691dd
commit
53fc25b7f5
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user