]> granicus.if.org Git - strace/commitdiff
printpath: do not fetch more than PATH_MAX bytes from tracee's memory
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 1 Aug 2017 20:59:48 +0000 (20:59 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 1 Aug 2017 20:59:48 +0000 (20:59 +0000)
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.

util.c

diff --git a/util.c b/util.c
index a08acc80bea876d68c06a82e3dedc5307fd877f2..68e6cdec950ce13ccda9ee7d9afd735b205fca11 100644 (file)
--- a/util.c
+++ b/util.c
@@ -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);
 }
 
 /*