From 77ad2555a365853784da46e09b248ef963cc1210 Mon Sep 17 00:00:00 2001 From: yar Date: Wed, 3 Nov 2004 06:52:40 +0000 Subject: Fix logxfer() by using realpath(3) instead of playing with getwd(3). Previously logxfer() used to record bogus pathnames to the log in some cases, namely, when cwd was / or "name" was absolute. Noticed by: Nick Leuta MFC after: 2 weeks --- libexec/ftpd/ftpd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'libexec/ftpd') diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index aeeaada..712f713 100644 --- a/libexec/ftpd/ftpd.c +++ b/libexec/ftpd/ftpd.c @@ -3169,15 +3169,19 @@ setproctitle(const char *fmt, ...) static void logxfer(char *name, off_t size, time_t start) { - char buf[1024]; + char buf[MAXPATHLEN + 1024]; char path[MAXPATHLEN + 1]; time_t now; - if (statfd >= 0 && getwd(path) != NULL) { + if (statfd >= 0) { time(&now); - snprintf(buf, sizeof(buf), "%.20s!%s!%s!%s/%s!%jd!%ld\n", + if (realpath(name, path) == NULL) { + syslog(LOG_NOTICE, "realpath failed on %s: %m", path); + return; + } + snprintf(buf, sizeof(buf), "%.20s!%s!%s!%s!%jd!%ld\n", ctime(&now)+4, ident, remotehost, - path, name, (intmax_t)size, + path, (intmax_t)size, (long)(now - start + (now == start))); write(statfd, buf, strlen(buf)); } -- cgit v1.1