提交 d59dd69d 编写于 作者: D Daniel T. Lee 提交者: 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: NDaniel T. Lee <danieltimlee@gmail.com>
Acked-by: NSong Liu <songliubraving@fb.com>
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
上级 90b1023f
...@@ -58,7 +58,9 @@ static int write_kprobe_events(const char *val) ...@@ -58,7 +58,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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册