Skip to content

Commit 2906063

Browse files
Binbin WuIngo Molnar
authored andcommitted
selftests/x86/lam: Zero out buffer for readlink()
Zero out the buffer for readlink() since readlink() does not append a terminating null byte to the buffer. Also change the buffer length passed to readlink() to 'PATH_MAX - 1' to ensure the resulting string is always null terminated. Fixes: 833c12c ("selftests/x86/lam: Add inherit test cases for linear-address masking") Signed-off-by: Binbin Wu <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Kirill A. Shutemov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d6f274b commit 2906063

File tree

1 file changed

+3
-3
lines changed
  • tools/testing/selftests/x86

1 file changed

+3
-3
lines changed

tools/testing/selftests/x86/lam.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ int do_uring(unsigned long lam)
573573
char path[PATH_MAX] = {0};
574574

575575
/* get current process path */
576-
if (readlink("/proc/self/exe", path, PATH_MAX) <= 0)
576+
if (readlink("/proc/self/exe", path, PATH_MAX - 1) <= 0)
577577
return 1;
578578

579579
int file_fd = open(path, O_RDONLY);
@@ -680,14 +680,14 @@ static int handle_execve(struct testcases *test)
680680
perror("Fork failed.");
681681
ret = 1;
682682
} else if (pid == 0) {
683-
char path[PATH_MAX];
683+
char path[PATH_MAX] = {0};
684684

685685
/* Set LAM mode in parent process */
686686
if (set_lam(lam) != 0)
687687
return 1;
688688

689689
/* Get current binary's path and the binary was run by execve */
690-
if (readlink("/proc/self/exe", path, PATH_MAX) <= 0)
690+
if (readlink("/proc/self/exe", path, PATH_MAX - 1) <= 0)
691691
exit(-1);
692692

693693
/* run binary to get LAM mode and return to parent process */

0 commit comments

Comments
 (0)