From 7825a53069172475d61bd42a2d426f3c2be43bc8 Mon Sep 17 00:00:00 2001 From: yar Date: Mon, 22 Jul 2002 07:41:14 +0000 Subject: Fix one RFC 959 incompliance: Double double-quotes in a PWD result if they appear in the directory pathname. PR: misc/18365 MFC after: 1 week --- libexec/ftpd/ftpd.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'libexec/ftpd') diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index 14ba477..fe83eca 100644 --- a/libexec/ftpd/ftpd.c +++ b/libexec/ftpd/ftpd.c @@ -252,6 +252,7 @@ static struct passwd * static char *sgetsave(char *); static void reapchild(int); static void logxfer(char *, off_t, time_t); +static char *doublequote(char *); static char * curdir(void) @@ -2327,12 +2328,16 @@ removedir(char *name) void pwd(void) { - char path[MAXPATHLEN + 1]; + char *s, path[MAXPATHLEN + 1]; if (getwd(path) == (char *)NULL) reply(550, "%s.", path); - else - reply(257, "\"%s\" is current directory.", path); + else { + if ((s = doublequote(path)) == NULL) + fatalerror("Ran out of memory."); + reply(257, "\"%s\" is current directory.", s); + free(s); + } } char * @@ -2917,3 +2922,25 @@ logxfer(char *name, off_t size, time_t start) write(statfd, buf, strlen(buf)); } } + +static char * +doublequote(char *s) +{ + int n; + char *p, *s2; + + for (p = s, n = 0; *p; p++) + if (*p == '"') + n++; + + if ((s2 = malloc(p - s + n + 1)) == NULL) + return (NULL); + + for (p = s2; *s; s++, p++) { + if ((*p = *s) == '"') + *(++p) = '"'; + } + *p = '\0'; + + return (s2); +} -- cgit v1.1