]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mime: allow partial lines as input
authorVictor Julien <vjulien@oisf.net>
Fri, 15 Apr 2022 13:49:09 +0000 (15:49 +0200)
committerVictor Julien <vjulien@oisf.net>
Thu, 21 Apr 2022 05:37:58 +0000 (07:37 +0200)
If we get a zero length delim we assume its a partial line and we
won't append CRLF just yet.

(cherry picked from commit 6e800a8548d9d2699589cac6afca3c0fa7613202)

src/util-decode-mime.c

index a9afb7623e5ebc0d987c3d19b1185c57e59b06a5..3b1cc4ab5c6ea9b42f9e435b2c441ceb01cf19cf 100644 (file)
@@ -1448,8 +1448,8 @@ static int ProcessQuotedPrintableBodyLine(const uint8_t *buf, uint32_t len,
             state->data_chunk_len++;
             entity->decoded_body_len += 1;
 
-            /* Add CRLF sequence if end of line */
-            if (remaining == 1) {
+            /* Add CRLF sequence if end of line, unless its a partial line */
+            if (remaining == 1 && state->current_line_delimiter_len > 0) {
                 memcpy(state->data_chunk + state->data_chunk_len, CRLF, EOL_LEN);
                 state->data_chunk_len += EOL_LEN;
                 entity->decoded_body_len += EOL_LEN;
@@ -1486,8 +1486,8 @@ static int ProcessQuotedPrintableBodyLine(const uint8_t *buf, uint32_t len,
                         state->data_chunk_len++;
                         entity->decoded_body_len++;
 
-                        /* Add CRLF sequence if end of line */
-                        if (remaining == 3) {
+                        /* Add CRLF sequence if end of line, unless for partial lines */
+                        if (remaining == 3 && state->current_line_delimiter_len > 0) {
                             memcpy(state->data_chunk + state->data_chunk_len,
                                     CRLF, EOL_LEN);
                             state->data_chunk_len += EOL_LEN;
@@ -1576,8 +1576,8 @@ static int ProcessBodyLine(const uint8_t *buf, uint32_t len,
             memcpy(state->data_chunk + state->data_chunk_len, buf + offset, tobuf);
             state->data_chunk_len += tobuf;
 
-            /* Now always add a CRLF to the end */
-            if (tobuf == remaining) {
+            /* 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;
             }