Skip to content

Commit d59dd69

Browse files
DanielTimLeeborkmann
authored andcommitted
samples: bpf: fix: seg fault with NULL pointer arg
When NULL pointer accidentally passed to write_kprobe_events, due to strlen(NULL), segmentation fault happens. Changed code returns -1 to deal with this situation. Bug issued with Smatch, static analysis. Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 90b1023 commit d59dd69

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

samples/bpf/bpf_load.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ static int write_kprobe_events(const char *val)
5858
{
5959
int fd, ret, flags;
6060

61-
if ((val != NULL) && (val[0] == '\0'))
61+
if (val == NULL)
62+
return -1;
63+
else if (val[0] == '\0')
6264
flags = O_WRONLY | O_TRUNC;
6365
else
6466
flags = O_WRONLY | O_APPEND;

0 commit comments

Comments
 (0)