Commit d59dd69d authored by Daniel T. Lee's avatar Daniel T. Lee Committed by Daniel Borkmann

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's avatarDaniel T. Lee <>
Acked-by: default avatarSong Liu <>
Signed-off-by: default avatarDaniel Borkmann <>
parent 90b1023f
......@@ -58,7 +58,9 @@ static int write_kprobe_events(const char *val)
int fd, ret, flags;
if ((val != NULL) && (val[0] == '\0'))
if (val == NULL)
return -1;
else if (val[0] == '\0')
flags = O_WRONLY | O_TRUNC;
flags = O_WRONLY | O_APPEND;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment