Skip to content

Commit f7c2d64

Browse files
Chang-Hsien Tsaiborkmann
authored andcommitted
samples, bpf: fix to change the buffer size for read()
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 <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent f7355a6 commit f7c2d64

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

samples/bpf/bpf_load.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ void read_trace_pipe(void)
678678
static char buf[4096];
679679
ssize_t sz;
680680

681-
sz = read(trace_fd, buf, sizeof(buf));
681+
sz = read(trace_fd, buf, sizeof(buf) - 1);
682682
if (sz > 0) {
683683
buf[sz] = 0;
684684
puts(buf);

0 commit comments

Comments
 (0)