]> git.baikalelectronics.ru Git - kernel.git/commit
selftests/bpf: test_progs: fix verbose mode garbage
authorStanislav Fomichev <sdf@google.com>
Sat, 31 Aug 2019 02:34:26 +0000 (19:34 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 3 Sep 2019 13:13:14 +0000 (15:13 +0200)
commitff91a1ae1ffb8355cc6744f3ad78c57bab254c52
tree2c3d5c5ca47d649db2a21bdbb00a459cba133efa
parent51fef07fb066fc824b1a84186ada28822f12aeb5
selftests/bpf: test_progs: fix verbose mode garbage

fseeko(.., 0, SEEK_SET) on a memstream just puts the buffer pointer
to the beginning so when we call fflush on it we get some garbage
log data from the previous test. Let's manually set terminating
byte to zero at the reported buffer size.

To show the issue consider the following snippet:

stream = open_memstream (&buf, &len);

fprintf(stream, "aaa");
fflush(stream);
printf("buf=%s, len=%zu\n", buf, len);
fseeko(stream, 0, SEEK_SET);

fprintf(stream, "b");
fflush(stream);
printf("buf=%s, len=%zu\n", buf, len);

Output:

buf=aaa, len=3
buf=baa, len=1

Fixes: f5968422c64f ("selftests/bpf: test_progs: switch to open_memstream")
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/testing/selftests/bpf/test_progs.c