]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
smtp: skip preprocessing for mime headers
authorVictor Julien <vjulien@oisf.net>
Sat, 25 Jun 2022 11:01:37 +0000 (13:01 +0200)
committerVictor Julien <vjulien@oisf.net>
Wed, 29 Jun 2022 20:56:34 +0000 (22:56 +0200)
Mime parser doesn't expect partial lines, which preprocessing can
provide. Add a check to let mime headers be handled by regular line
parsing.

(cherry picked from commit a38f2f2a52822f150fff0d5e17e9f62582d6558c)

src/app-layer-smtp.c
src/util-decode-mime.c

index a8bc8a8bd8fc117be182120682b286d8afc70d1b..7a68867e51e738d01fcedc8ff87d532ae1bc8f4b 100644 (file)
@@ -1411,6 +1411,12 @@ static int SMTPProcessRequest(SMTPState *state, Flow *f,
 static int SMTPPreProcessCommands(SMTPState *state, Flow *f, AppLayerParserState *pstate)
 {
     DEBUG_VALIDATE_BUG_ON((state->parser_state & SMTP_PARSER_STATE_COMMAND_DATA_MODE) == 0);
+
+    /* fall back to strict line parsing for mime header parsing */
+    if (state->curr_tx && state->curr_tx->mime_state &&
+            state->curr_tx->mime_state->state_flag < HEADER_DONE)
+        return 1;
+
     if (state->ts_db_len) {
         /* bail and yield to SMTPGetLine if:
          * possible incomplete end of data */
index 37b286d663c4b43861732df8ed3dc94cf962896a..edbd666ec8bcb2c6cb83d40784a0b9c40f15af08 100644 (file)
@@ -1694,6 +1694,9 @@ static int FindMimeHeader(const uint8_t *buf, uint32_t blen,
     int finish_header = 0, new_header = 0;
     MimeDecConfig *mdcfg = MimeDecGetConfig();
 
+    /* should not get here with incomplete lines */
+    DEBUG_VALIDATE_BUG_ON(state->current_line_delimiter_len == 0);
+
     /* Find first header */
     hname = FindMimeHeaderStart(buf, blen, &hlen);
     if (hname != NULL) {