app/ftp: Eliminate scan-build warning

Scan-build reports that FTPRealloc could be called with size=0. Modify
the logic so it's never passed 0.
pull/12980/head
Jeff Lucovsky 4 months ago committed by Jason Ish
parent 88c38fc4a0
commit fdc43e5ac4

@ -130,7 +130,6 @@ static void *FTPCalloc(size_t n, size_t size)
static void *FTPRealloc(void *ptr, size_t orig_size, size_t size) static void *FTPRealloc(void *ptr, size_t orig_size, size_t size)
{ {
DEBUG_VALIDATE_BUG_ON(size == 0);
if (FTPCheckMemcap((uint32_t)(size - orig_size)) == 0) { if (FTPCheckMemcap((uint32_t)(size - orig_size)) == 0) {
sc_errno = SC_ELIMIT; sc_errno = SC_ELIMIT;
return NULL; return NULL;
@ -480,7 +479,7 @@ static AppLayerResult FTPParseRequest(Flow *f, void *ftp_state, AppLayerParserSt
case FTP_COMMAND_PORT: case FTP_COMMAND_PORT:
if (line.len + 1 > state->port_line_size) { if (line.len + 1 > state->port_line_size) {
/* Allocate an extra byte for a NULL terminator */ /* Allocate an extra byte for a NULL terminator */
ptmp = FTPRealloc(state->port_line, state->port_line_size, line.len); ptmp = FTPRealloc(state->port_line, state->port_line_size, line.len + 1);
if (ptmp == NULL) { if (ptmp == NULL) {
if (state->port_line) { if (state->port_line) {
FTPFree(state->port_line, state->port_line_size); FTPFree(state->port_line, state->port_line_size);
@ -491,7 +490,7 @@ static AppLayerResult FTPParseRequest(Flow *f, void *ftp_state, AppLayerParserSt
SCReturnStruct(APP_LAYER_OK); SCReturnStruct(APP_LAYER_OK);
} }
state->port_line = ptmp; state->port_line = ptmp;
state->port_line_size = line.len; state->port_line_size = line.len + 1;
} }
memcpy(state->port_line, line.buf, line.len); memcpy(state->port_line, line.buf, line.len);
state->port_line_len = line.len; state->port_line_len = line.len;

Loading…
Cancel
Save