Commit 335d4f81 authored by Daniel T. Lee's avatar Daniel T. Lee Committed by Greg Kroah-Hartman

samples: bpf: fix: seg fault with NULL pointer arg

[ Upstream commit d59dd69d ]

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: default avatarDaniel T. Lee <danieltimlee@gmail.com>
Acked-by: default avatarSong Liu <songliubraving@fb.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent c41f30e8
...@@ -59,7 +59,9 @@ static int write_kprobe_events(const char *val) ...@@ -59,7 +59,9 @@ static int write_kprobe_events(const char *val)
{ {
int fd, ret, flags; 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_TRUNC;
else else
flags = O_WRONLY | O_APPEND; 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