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

Petr Vorel pvorel@suse.cz
Wed Jan 22 11:26:48 CET 2025


Hi Sven,

> 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.

Looks reasonable to me.
Reviewed-by: Petr Vorel <pvorel@suse.cz>

@Cyril a candidate for merge before the release.

Kind regards,
Petr

> 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));


More information about the ltp mailing list