Commit a5755141 authored by Chang-Hsien Tsai's avatar Chang-Hsien Tsai Committed by Greg Kroah-Hartman

samples, bpf: fix to change the buffer size for read()

[ Upstream commit f7c2d64b ]

If the trace for read is larger than 4096, the return
value sz will be 4096. This results in off-by-one error
on buf:

    static char buf[4096];
    ssize_t sz;

    sz = read(trace_fd, buf, sizeof(buf));
    if (sz > 0) {
        buf[sz] = 0;
        puts(buf);
    }
Signed-off-by: default avatarChang-Hsien Tsai <luke.tw@gmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent e87dee8d
...@@ -678,7 +678,7 @@ void read_trace_pipe(void) ...@@ -678,7 +678,7 @@ void read_trace_pipe(void)
static char buf[4096]; static char buf[4096];
ssize_t sz; ssize_t sz;
sz = read(trace_fd, buf, sizeof(buf)); sz = read(trace_fd, buf, sizeof(buf) - 1);
if (sz > 0) { if (sz > 0) {
buf[sz] = 0; buf[sz] = 0;
puts(buf); puts(buf);
......
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