diff options
author | Yaroslav Tykhiy <ytykhiy@gmail.com> | 2002-07-22 07:41:14 +0000 |
---|---|---|
committer | Yaroslav Tykhiy <ytykhiy@gmail.com> | 2002-07-22 07:41:14 +0000 |
commit | e4648f051fbd60eb5d1af9034d5cdc82a59dd2a4 (patch) | |
tree | 3047e95d254ac409293316488d89074a5a097acb /libexec | |
parent | bf038c87af5ff076ace1bd7a51bb9b79c75db5e3 (diff) | |
download | src-e4648f051fbd60eb5d1af9034d5cdc82a59dd2a4.tar.gz src-e4648f051fbd60eb5d1af9034d5cdc82a59dd2a4.zip |
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
Notes
Notes:
svn path=/head/; revision=100486
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/ftpd/ftpd.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index 14ba47766691..fe83ecaf9031 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); +} |