]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/ftp: FTP memory accounting fixes
authorJeff Lucovsky <jeff@lucovsky.org>
Tue, 21 Apr 2020 14:36:27 +0000 (10:36 -0400)
committerVictor Julien <victor@inliniac.net>
Thu, 23 Apr 2020 18:55:30 +0000 (20:55 +0200)
This commit continues the work started by @vanlink and corrects the
accounting of FTP memory usage against the memcap limit.

src/app-layer-ftp.c
src/output-json-ftp.c

index ef1fb0d5b0ed3a6f7e4c284a596e9e5227cfbe52..367bbae66da87987f80659e7092f6d6286fed7ed 100644 (file)
@@ -344,7 +344,7 @@ static void FTPTransactionFree(FTPTransaction *tx)
         FTPStringFree(str);
     }
 
-    SCFree(tx);
+    FTPFree(tx, sizeof(*tx));
 }
 
 static int FTPGetLineForDirection(FtpState *state, FtpLineState *line_state)
@@ -513,7 +513,7 @@ static void FtpTransferCmdFree(void *data)
     if (cmd == NULL)
         return;
     if (cmd->file_name) {
-        FTPFree(cmd->file_name, cmd->file_len);
+        FTPFree(cmd->file_name, cmd->file_len + 1);
     }
     FTPFree(cmd, sizeof(struct FtpTransferCmd));
 }
@@ -536,7 +536,7 @@ static uint32_t CopyCommandLine(uint8_t **dest, const uint8_t *src, uint32_t len
         *dest = where;
     }
     /* either 0 or actual */
-    return length;
+    return length ? length + 1 : 0;
 }
 
 
@@ -1195,12 +1195,12 @@ static void FTPDataStateFree(void *s)
         DetectEngineStateFree(fstate->de_state);
     }
     if (fstate->file_name != NULL) {
-        FTPFree(fstate->file_name, fstate->file_len);
+        FTPFree(fstate->file_name, fstate->file_len + 1);
     }
 
     FileContainerFree(fstate->files);
 
-    SCFree(s);
+    FTPFree(s, sizeof(FtpDataState));
 #ifdef DEBUG
     SCMutexLock(&ftpdata_state_mem_lock);
     ftpdata_state_memcnt--;
index 8d4a087bdab6e6352ba4070f3293e0cf9fcb6558..cd34ed61aa4bcd45c6a988d07a5e0d5ef6a50e5d 100644 (file)
@@ -99,7 +99,7 @@ static json_t *JsonFTPLogCommand(Flow *f, FTPTransaction *tx)
         TAILQ_FOREACH(response, &tx->response_list, next) {
             /* handle multiple lines within the response, \r\n delimited */
             uint8_t *where = response->str;
-            uint16_t length = response->len;
+            uint16_t length = response->len ? response->len -1 : 0;
             uint16_t pos;
             while ((pos = JsonGetNextLineFromBuffer((const char *)where, length)) != UINT16_MAX) {
                 uint16_t offset = 0;