]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app/ftp: Eliminate scan-build warning
authorJeff Lucovsky <jlucovsky@oisf.net>
Fri, 28 Mar 2025 14:12:59 +0000 (10:12 -0400)
committerJason Ish <jason.ish@oisf.net>
Mon, 7 Apr 2025 21:25:04 +0000 (15:25 -0600)
Scan-build reports that FTPRealloc could be called with size=0. Modify
the logic so it's never passed 0.

src/app-layer-ftp.c

index 7541214335fe19c238205414b2246abf037fb856..31cdd1e146120fd4ffbdc466c7c12ccdc19cfe0f 100644 (file)
@@ -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)
 {
-    DEBUG_VALIDATE_BUG_ON(size == 0);
     if (FTPCheckMemcap((uint32_t)(size - orig_size)) == 0) {
         sc_errno = SC_ELIMIT;
         return NULL;
@@ -480,7 +479,7 @@ static AppLayerResult FTPParseRequest(Flow *f, void *ftp_state, AppLayerParserSt
             case FTP_COMMAND_PORT:
                 if (line.len + 1 > state->port_line_size) {
                     /* 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 (state->port_line) {
                             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);
                     }
                     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);
                 state->port_line_len = line.len;