From: Dmitry V. Levin Date: Tue, 1 Aug 2017 20:59:48 +0000 (+0000) Subject: printpath: do not fetch more than PATH_MAX bytes from tracee's memory X-Git-Tag: v4.19~190 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d7a45f8dcce557f1c7b876dd22af8f2e7daf1bb1;p=strace 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. --- diff --git a/util.c b/util.c index a08acc80..68e6cdec 100644 --- 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); } /*