From: Victor Julien Date: Wed, 1 May 2019 14:36:50 +0000 (+0200) Subject: ftp: fix realloc handling to avoid valgrind warning X-Git-Tag: suricata-5.0.0-rc1~527 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ae2edb22ad974ab6c4391e61022051410181b85;p=thirdparty%2Fsuricata.git ftp: fix realloc handling to avoid valgrind warning Bug #2951 --- diff --git a/src/app-layer-ftp.c b/src/app-layer-ftp.c index 782a9c6ec0..67a7c41a23 100644 --- a/src/app-layer-ftp.c +++ b/src/app-layer-ftp.c @@ -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: