diff options
author | Chang-Hsien Tsai <luke.tw@gmail.com> | 2019-05-19 12:05:44 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-07-21 10:05:51 +0300 |
commit | 95a21e78295beed805a037669bcb20489cf14109 (patch) | |
tree | ce9ea074378cd84f29a9023ce6fce07edcee7d28 /samples | |
parent | f36d287a761cd19825ba3b581d797e30e6572909 (diff) | |
download | linux-95a21e78295beed805a037669bcb20489cf14109.tar.xz |
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>
Diffstat (limited to 'samples')
-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 97913e109b14..99e5a2f63e76 100644 --- a/samples/bpf/bpf_load.c +++ b/samples/bpf/bpf_load.c @@ -369,7 +369,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); |