[PATCH 2/3] ftpd: Deal with too long command lines

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Oct 30 11:09:26 UTC 2018


Update #3530.
---
 cpukit/ftpd/ftpd.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/cpukit/ftpd/ftpd.c b/cpukit/ftpd/ftpd.c
index eb87612bb5..8aef440a72 100644
--- a/cpukit/ftpd/ftpd.c
+++ b/cpukit/ftpd/ftpd.c
@@ -1908,6 +1908,7 @@ session(rtems_task_argument arg)
       {
         char buf[FTPD_BUFSIZE];
         char *cmd, *opts, *args;
+        size_t len;
 
         if (fgets(buf, FTPD_BUFSIZE, info->ctrl_fp) == NULL)
         {
@@ -1915,6 +1916,25 @@ session(rtems_task_argument arg)
           break;
         }
 
+        len = strlen(buf);
+
+        if (len == 0)
+          continue;
+
+        if (buf[len - 1] != '\n')
+        {
+          send_reply(info, 501, "Command line too long.");
+
+          /*
+           * We could also try to continue here, however, discarding the rest
+           * of the current command line and figuring out when the next command
+           * starts with fgets() is not that easy.  It would be better to avoid
+           * the FILE stream and just use the socket directly with send() and
+           * recv().
+           */
+          break;
+        }
+
         split_command(buf, &cmd, &opts, &args);
 
         if (!strcmp("QUIT", cmd))
-- 
2.16.4




More information about the devel mailing list