Browse Source

ftp: corrected insane limit on telnet cmd argument len

also further purged redundant strlen invocations
Sergey Alirzaev 4 years ago
parent
commit
52630269e7
1 changed files with 8 additions and 15 deletions
  1. 8 15
      modules/cli/CLI_Commands.c

+ 8 - 15
modules/cli/CLI_Commands.c

@@ -2883,33 +2883,29 @@ static portBASE_TYPE prvTaskFTPCommand(cli_state_t *cli_state, int8_t *pcWriteBu
         return pdFALSE;
         return pdFALSE;
     }
     }
 
 
-    /* Obtain the parameter string. */
+    /* Obtain the subcommand */
     pcParameterString = (int8_t *)FreeRTOS_CLIGetParameter
     pcParameterString = (int8_t *)FreeRTOS_CLIGetParameter
         (
         (
             pcCommandString,        /* The command string itself. */
             pcCommandString,        /* The command string itself. */
             xParameterNumber,       /* Return the next parameter. */
             xParameterNumber,       /* Return the next parameter. */
             &xParameterStringLength /* Store the parameter string length. */
             &xParameterStringLength /* Store the parameter string length. */
         );
         );
-    for (i = 0; i < ARG_FTP_ALL; i ++) {
+    for (i = 0; i < ARG_FTP_ALL; i++) {
         if (strncmp((const char *)pcParameterString, ftp_args_list[i], strlen(ftp_args_list[i])) == 0
         if (strncmp((const char *)pcParameterString, ftp_args_list[i], strlen(ftp_args_list[i])) == 0
             && xParameterStringLength == strlen(ftp_args_list[i])) {
             && xParameterStringLength == strlen(ftp_args_list[i])) {
             break;
             break;
         }
         }
     }
     }
-    xParameterNumber ++;
+    xParameterNumber++;
 
 
-    /* Obtain the parameter string. */
-    pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
+    /* Obtain the subcommand parameter */
+    pcParameterString = (int8_t *)FreeRTOS_CLIGetParameter
         (
         (
             pcCommandString,        /* The command string itself. */
             pcCommandString,        /* The command string itself. */
             xParameterNumber,       /* Return the next parameter. */
             xParameterNumber,       /* Return the next parameter. */
             &xParameterStringLength /* Store the parameter string length. */
             &xParameterStringLength /* Store the parameter string length. */
         );
         );
     memset(str, 0, sizeof(str));
     memset(str, 0, sizeof(str));
-    if (xParameterStringLength > 3) {
-        strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
-        return pdFALSE;
-    }
     strncat(str, (const char *) pcParameterString, xParameterStringLength);
     strncat(str, (const char *) pcParameterString, xParameterStringLength);
 
 
     switch (i) {
     switch (i) {
@@ -2939,8 +2935,7 @@ static portBASE_TYPE prvTaskFTPCommand(cli_state_t *cli_state, int8_t *pcWriteBu
             }
             }
             break;
             break;
         case ARG_FTP_remote_path: {
         case ARG_FTP_remote_path: {
-            unsigned len = strlen(str);
-            if (len < 1 || len >= sizeof(sSettings.sFTPUpdate.remote_path)) {
+            if (xParameterStringLength < 1 || xParameterStringLength >= sizeof(sSettings.sFTPUpdate.remote_path)) {
                 strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
                 strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
                 return pdFALSE;
                 return pdFALSE;
             } else {
             } else {
@@ -2949,8 +2944,7 @@ static portBASE_TYPE prvTaskFTPCommand(cli_state_t *cli_state, int8_t *pcWriteBu
             }
             }
             break; }
             break; }
         case ARG_FTP_user: {
         case ARG_FTP_user: {
-            unsigned len = strlen(str);
-            if (len < 1 || len >= sizeof(sSettings.sFTPUpdate.user)) {
+            if (xParameterStringLength < 1 || xParameterStringLength >= sizeof(sSettings.sFTPUpdate.user)) {
                 strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
                 strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
                 return pdFALSE;
                 return pdFALSE;
             } else {
             } else {
@@ -2959,8 +2953,7 @@ static portBASE_TYPE prvTaskFTPCommand(cli_state_t *cli_state, int8_t *pcWriteBu
             }
             }
             break; }
             break; }
         case ARG_FTP_pass: {
         case ARG_FTP_pass: {
-            unsigned len = strlen(str);
-            if (len < 1 || len >= sizeof(sSettings.sFTPUpdate.pass)) {
+            if (xParameterStringLength < 1 || xParameterStringLength >= sizeof(sSettings.sFTPUpdate.pass)) {
                 strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
                 strcpy((char *)pcWriteBuffer, (const char *)pcInvalidCommand);
                 return pdFALSE;
                 return pdFALSE;
             } else {
             } else {