Skip to content

Commit c479f5e

Browse files
ahjf-07Kernel Patches Daemon
authored andcommitted
selftests/bpf: Fix read_iter buffer termination in test_bpffs
read_iter() always NUL-terminated at the end of the buffer, so strstr() could scan uninitialized stack bytes on short reads. Terminate at len and use O_RDONLY. Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
1 parent ebefa82 commit c479f5e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tools/testing/selftests/bpf/prog_tests/test_bpffs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ static int read_iter(char *file)
1717
char buf[1024];
1818
int fd, len;
1919

20-
fd = open(file, 0);
20+
fd = open(file, O_RDONLY);
2121
if (fd < 0)
2222
return -1;
23-
while ((len = read(fd, buf, sizeof(buf))) > 0) {
24-
buf[sizeof(buf) - 1] = '\0';
23+
while ((len = read(fd, buf, sizeof(buf) - 1)) > 0) {
24+
buf[len] = '\0';
2525
if (strstr(buf, "iter")) {
2626
close(fd);
2727
return 0;

0 commit comments

Comments
 (0)