summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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