summaryrefslogtreecommitdiffstats
path: root/libexec/ftpd
diff options
context:
space:
mode:
authoryar <yar@FreeBSD.org>2002-07-22 07:41:14 +0000
committeryar <yar@FreeBSD.org>2002-07-22 07:41:14 +0000
commit7825a53069172475d61bd42a2d426f3c2be43bc8 (patch)
tree3047e95d254ac409293316488d89074a5a097acb /libexec/ftpd
parenta76817b7416c637546707909fdf26597a09a856e (diff)
downloadFreeBSD-src-7825a53069172475d61bd42a2d426f3c2be43bc8.zip
FreeBSD-src-7825a53069172475d61bd42a2d426f3c2be43bc8.tar.gz
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
Diffstat (limited to 'libexec/ftpd')
-rw-r--r--libexec/ftpd/ftpd.c33
1 files changed, 30 insertions, 3 deletions
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);
+}
OpenPOWER on IntegriCloud