public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] mmap04: Make sure the scanf address format is at least 8 hex chars
@ 2025-09-18 15:26 Mark Wielaard
  2025-09-18 15:30 ` Mark Wielaard
  2025-09-22  7:48 ` Cyril Hrubis
  0 siblings, 2 replies; 6+ messages in thread
From: Mark Wielaard @ 2025-09-18 15:26 UTC (permalink / raw)
  To: ltp; +Cc: Mark Wielaard, Martin Cermak

The addresses in /proc/self/maps are at least 8 hex chars. Zeros are
added to the front of the address when shorted (both on 32bit and
64bit systems.

Under valgrind the mmaps used in kernel/syscalls/mmap/mmap04.c come
out very low in the address space and might be shorter than 8 hex
chars. This causes the scanf to fail:
mmap04.c:62: TBROK: Expected 1 conversions got 0 FILE '/proc/self/maps'

Fix this by using "%08" PRIxPTR when creating the fmt used.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 testcases/kernel/syscalls/mmap/mmap04.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/mmap/mmap04.c b/testcases/kernel/syscalls/mmap/mmap04.c
index 4a050b7b50da..5b28180df29b 100644
--- a/testcases/kernel/syscalls/mmap/mmap04.c
+++ b/testcases/kernel/syscalls/mmap/mmap04.c
@@ -58,7 +58,8 @@ static void run(unsigned int i)
 
 	addr2 = SAFE_MMAP(addr1 + pagesize, pagesize, tc->prot, tc->flags | MAP_FIXED, -1, 0);
 
-	sprintf(fmt, "%" PRIxPTR "-%%*x %%s", (uintptr_t)addr2);
+	/* A /proc/self/maps address is at least 8 hex (left zero padded) */
+	sprintf(fmt, "%08" PRIxPTR "-%%*x %%s", (uintptr_t)addr2);
 	SAFE_FILE_LINES_SCANF("/proc/self/maps", fmt, perms);
 
 	if (!strcmp(perms, tc->exp_perms)) {
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-09-22 21:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-18 15:26 [LTP] [PATCH] mmap04: Make sure the scanf address format is at least 8 hex chars Mark Wielaard
2025-09-18 15:30 ` Mark Wielaard
2025-09-22  7:48 ` Cyril Hrubis
2025-09-22  8:24   ` Mark Wielaard
2025-09-22  8:33     ` Cyril Hrubis
2025-09-22 21:26       ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox