Skip to content

Commit 53fc25b

Browse files
Chenyuan Minamhyung
authored andcommitted
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 <[email protected]> Acked-by: Ian Rogers <[email protected]> Cc: Leo Yan <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 240de69 commit 53fc25b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

tools/lib/subcmd/help.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
void add_cmdname(struct cmdnames *cmds, const char *name, size_t len)
1717
{
1818
struct cmdname *ent = malloc(sizeof(*ent) + len + 1);
19+
if (!ent)
20+
return;
1921

2022
ent->len = len;
2123
memcpy(ent->name, name, len);

0 commit comments

Comments
 (0)