printpath: do not fetch more than PATH_MAX bytes from tracee's memory

The kernel does not copy more than PATH_MAX bytes from userspace
pathnames, treating non-NUL-terminated pathnames as ENAMETOOLONG.

* util.c (printpathn): Decrease buffer size to PATH_MAX.
(printpath): Specify PATH_MAX - 1 as the maximum pathname length
to match the kernel behaviour.  The underlying umovestr call will fetch
up to PATH_MAX bytes from tracee's memory, but no more than first
PATH_MAX - 1 bytes will be printed.
This commit is contained in:
Дмитрий Левин 2017-08-01 20:59:48 +00:00
parent ce822389af
commit d7a45f8dcc

4
util.c
View File

@ -715,7 +715,7 @@ print_quoted_cstring(const char *str, unsigned int size)
void
printpathn(struct tcb *const tcp, const kernel_ulong_t addr, unsigned int n)
{
char path[PATH_MAX + 1];
char path[PATH_MAX];
int nul_seen;
if (!addr) {
@ -741,7 +741,7 @@ void
printpath(struct tcb *const tcp, const kernel_ulong_t addr)
{
/* Size must correspond to char path[] size in printpathn */
printpathn(tcp, addr, PATH_MAX);
printpathn(tcp, addr, PATH_MAX - 1);
}
/*