]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mime: properly pass full lines to non-decoded body
authorVictor Julien <vjulien@oisf.net>
Mon, 27 Jun 2022 18:15:16 +0000 (20:15 +0200)
committerVictor Julien <vjulien@oisf.net>
Wed, 29 Jun 2022 20:57:55 +0000 (22:57 +0200)
Use actual delim count and make sure we also pass on empty lines
(so delim(s) only).

(cherry picked from commit b82b8825e79bd43901720813b672a9ff5c7bf120)

src/util-decode-mime.c

index 0586eda47f405f5d700ac36e14673ade7f923811..7e144ca0200dbef77aac693d7ebd2d929ff3ebe7 100644 (file)
@@ -1576,7 +1576,7 @@ static int ProcessBodyLine(const uint8_t *buf, uint32_t len,
     SCLogDebug("Processing body line");
 
     /* Track length */
-    entity->body_len += len + 2; /* With CRLF */
+    entity->body_len += (len + state->current_line_delimiter_len);
 
     /* Process base-64 content if enabled */
     MimeDecConfig *mdcfg = MimeDecGetConfig();
@@ -1597,24 +1597,17 @@ static int ProcessBodyLine(const uint8_t *buf, uint32_t len,
         }
     } else {
         /* Process non-decoded content */
-        remaining = len;
+        remaining = len + state->current_line_delimiter_len;
         offset = 0;
         while (remaining > 0) {
-
             /* Plan to add CRLF to the end of each line */
             avail = DATA_CHUNK_SIZE - state->data_chunk_len;
-            tobuf = avail > remaining + EOL_LEN ? remaining : avail - EOL_LEN;
+            tobuf = avail > remaining ? remaining : avail;
 
             /* Copy over to buffer */
             memcpy(state->data_chunk + state->data_chunk_len, buf + offset, tobuf);
             state->data_chunk_len += tobuf;
 
-            /* Now always add a CRLF to the end, unless its a partial line */
-            if (tobuf == remaining && state->current_line_delimiter_len > 0) {
-                memcpy(state->data_chunk + state->data_chunk_len, CRLF, EOL_LEN);
-                state->data_chunk_len += EOL_LEN;
-            }
-
             if ((int) (DATA_CHUNK_SIZE - state->data_chunk_len) < 0) {
                 SCLogDebug("Error: Invalid Chunk length: %u",
                         state->data_chunk_len);
@@ -1623,8 +1616,7 @@ static int ProcessBodyLine(const uint8_t *buf, uint32_t len,
             }
 
             /* If buffer full, then invoke callback */
-            if (DATA_CHUNK_SIZE - state->data_chunk_len < EOL_LEN + 1) {
-
+            if (DATA_CHUNK_SIZE - state->data_chunk_len == 0) {
                 /* Invoke pre-processor and callback */
                 ret = ProcessDecodedDataChunk(state->data_chunk,
                         state->data_chunk_len, state);
@@ -2310,11 +2302,6 @@ static int ProcessMimeBody(const uint8_t *buf, uint32_t len,
     }
 #endif
 
-    /* Ignore empty lines */
-    if (len == 0) {
-        return ret;
-    }
-
     /* First look for boundary */
     MimeDecStackNode *node = state->stack->top;
     if (node == NULL) {