]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
ftp: fix realloc handling to avoid valgrind warning
authorVictor Julien <victor@inliniac.net>
Wed, 1 May 2019 14:36:50 +0000 (16:36 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 3 May 2019 10:35:36 +0000 (12:35 +0200)
Bug #2951

src/app-layer-ftp.c

index 782a9c6ec05721cbf14dcbbe64bb30ec04c7e804..67a7c41a23f27aa4a1382bed879ef5c036e4d48c 100644 (file)
@@ -476,7 +476,7 @@ static int FTPParseRequest(Flow *f, void *ftp_state,
             case FTP_COMMAND_EPRT:
                 // fallthrough
             case FTP_COMMAND_PORT:
-                if (state->current_line_len > state->port_line_size) {
+                if (state->current_line_len + 1 > state->port_line_size) {
                     /* Allocate an extra byte for a NULL terminator */
                     ptmp = FTPRealloc(state->port_line, state->port_line_size,
                                       state->current_line_len + 1);
@@ -493,6 +493,7 @@ static int FTPParseRequest(Flow *f, void *ftp_state,
                 }
                 memcpy(state->port_line, state->current_line,
                         state->current_line_len);
+                state->port_line[state->current_line_len] = '\0';
                 state->port_line_len = state->current_line_len;
                 break;
             case FTP_COMMAND_RETR: