[LTP] [PATCH] mmap01: initialize buffer in check_file()

Sven Schnelle svens@linux.ibm.com
Wed Jan 22 11:09:14 CET 2025


mmap01 reported random test failures. Turns out the
the temporary buffer in check_file() isn't initialized.
The SAFE_READ reads less then sizeof(buf) bytes so the
rest stays initialized and might contain bytes check_file()
is looking for.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
---
 testcases/kernel/syscalls/mmap/mmap01.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/testcases/kernel/syscalls/mmap/mmap01.c b/testcases/kernel/syscalls/mmap/mmap01.c
index c93c37ceda52..ff09bc635c74 100644
--- a/testcases/kernel/syscalls/mmap/mmap01.c
+++ b/testcases/kernel/syscalls/mmap/mmap01.c
@@ -36,6 +36,7 @@ static void check_file(void)
 	int i, fildes, buf_len = sizeof(STRING) + 3;
 	char buf[buf_len];
 
+	memset(buf, 0, sizeof(buf));
 	fildes = SAFE_OPEN(TEMPFILE, O_RDONLY);
 	SAFE_READ(0, fildes, buf, sizeof(buf));
 
-- 
2.47.1



More information about the ltp mailing list