Skip to content

Commit d444b06

Browse files
tklauserborkmann
authored andcommitted
bpftool: Check malloc return value in mount_bpffs_for_pin
Fix and add a missing NULL check for the prior malloc() call. Fixes: 49a086c ("bpftool: implement prog load command") Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Quentin Monnet <quentin@isovalent.com> Acked-by: Roman Gushchin <guro@fb.com> Link: https://lore.kernel.org/bpf/20210715110609.29364-1-tklauser@distanz.ch
1 parent 54ea2f4 commit d444b06

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tools/bpf/bpftool/common.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ int mount_bpffs_for_pin(const char *name)
222222
int err = 0;
223223

224224
file = malloc(strlen(name) + 1);
225+
if (!file) {
226+
p_err("mem alloc failed");
227+
return -1;
228+
}
229+
225230
strcpy(file, name);
226231
dir = dirname(file);
227232

0 commit comments

Comments
 (0)