diff options
author | Chang-Hsien Tsai <luke.tw@gmail.com> | 2019-05-19 09:05:44 +0000 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-07-14 08:11:04 +0200 |
commit | e7779115bbd9a89a1286104b7a2821a1e2009355 (patch) | |
tree | ba88202be044dcbc5b77d3de902f9eafb43eed93 | |
parent | fe01e93c3fd1d6a05a78ce105ce49f9bd3d5c596 (diff) | |
download | linux-stable-e7779115bbd9a89a1286104b7a2821a1e2009355.tar.gz linux-stable-e7779115bbd9a89a1286104b7a2821a1e2009355.tar.bz2 linux-stable-e7779115bbd9a89a1286104b7a2821a1e2009355.zip |
samples, bpf: fix to change the buffer size for read()
[ Upstream commit f7c2d64bac1be2ff32f8e4f500c6e5429c1003e0 ]
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: Chang-Hsien Tsai <luke.tw@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | samples/bpf/bpf_load.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c index cf40a8284a38..5061a2ec4564 100644 --- a/samples/bpf/bpf_load.c +++ b/samples/bpf/bpf_load.c @@ -677,7 +677,7 @@ void read_trace_pipe(void) static char buf[4096]; ssize_t sz; - sz = read(trace_fd, buf, sizeof(buf)); + sz = read(trace_fd, buf, sizeof(buf) - 1); if (sz > 0) { buf[sz] = 0; puts(buf); |