[LTP] [PATCH] mmap04: Make sure the scanf address format is at least 8 hex chars

Petr Vorel pvorel@suse.cz
Mon Sep 22 23:26:45 CEST 2025


Hi Mark, Cyril,

> Hi!
> > > > 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'

> > > I guess I do not understand the problem here. The PRIxPTR translates to
> > > "x", "lx", or "llx" depending on architecture and as far as I can tell
> > > the %x modifier handles leading zeroes just fine.

> > The problem is that we want to match (scanf) an absolute address
> > (addr2) at the start of the line. It is this absolute/literal address
> > that doesn't match (because it might not have leading zeros).

> > e.g. We might want to match the address 403a000 and want to match
> > against: 0403a000-04048000 rw-p

> > When creating the fmt which we want to use for scanf we currently
> > generate: "403a000-%*x %s" Which doesn't match because it is missing
> > the leading zero (the "-%*x %s" would match the rest, except that the
> > start of the line doesn't). So with the "%08" fix we would generate:
> > "0403a000-%*x %s" which does match because it has the same number of
> > leading zeros.

> Ah right, I'm blind, we generate the fmt on the fly. In that case
> padding to eight zeroes will match what kernel does.

Mark, thanks for fixing our test! Merged.

Kind regards,
Petr


More information about the ltp mailing list