From a38f2f2a52822f150fff0d5e17e9f62582d6558c Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sat, 25 Jun 2022 13:01:37 +0200 Subject: [PATCH] smtp: skip preprocessing for mime headers Mime parser doesn't expect partial lines, which preprocessing can provide. Add a check to let mime headers be handled by regular line parsing. --- src/app-layer-smtp.c | 5 +++++ src/util-decode-mime.c | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/app-layer-smtp.c b/src/app-layer-smtp.c index 44706b96e6..038800f9a2 100644 --- a/src/app-layer-smtp.c +++ b/src/app-layer-smtp.c @@ -1275,6 +1275,11 @@ static int SMTPPreProcessCommands( { 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; + bool line_complete = false; const int32_t input_len = input->len; for (int32_t i = 0; i < input_len; i++) { diff --git a/src/util-decode-mime.c b/src/util-decode-mime.c index 80fd9d9da6..64e300c9cc 100644 --- a/src/util-decode-mime.c +++ b/src/util-decode-mime.c @@ -1706,6 +1706,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) {