[PATCH 3/6] ftpd: Avoid malloc() and sscanf()

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Oct 5 13:43:44 UTC 2018


Move the user name to the session information.

Update #3530.
---
 cpukit/ftpd/ftpd.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/cpukit/ftpd/ftpd.c b/cpukit/ftpd/ftpd.c
index fb67335c0c..25656134fb 100644
--- a/cpukit/ftpd/ftpd.c
+++ b/cpukit/ftpd/ftpd.c
@@ -265,6 +265,7 @@ typedef struct
   int                 xfer_mode;   /* Transfer mode (ASCII/binary) */
   rtems_id            tid;         /* Task id */
   char                *user;       /* user name (0 if not supplied) */
+  char                user_buf[256]; /* user name buffer */
   bool                auth;        /* true if user/pass was valid, false if not or not supplied */
 } FTPD_SessionInfo_t;
 
@@ -1736,9 +1737,8 @@ exec_command(FTPD_SessionInfo_t *info, char* cmd, char* args)
   }
   else if (!strcmp("USER", cmd))
   {
-    sscanf(args, "%254s", fname);
-    free(info->user);
-    info->user = strdup(fname);
+    strlcpy(info->user_buf, args, sizeof(info->user_buf));
+    info->user = info->user_buf;
     if (ftpd_config->login &&
       !ftpd_config->login(info->user, NULL)) {
       info->auth = false;
@@ -1944,7 +1944,6 @@ session(rtems_task_argument arg)
     /* Close connection and put ourselves back into the task pool. */
     close_data_socket(info);
     close_stream(info);
-    free(info->user);
     task_pool_release(info);
   }
 }
-- 
2.16.4




More information about the devel mailing list