smtp/mime: consolidate a MimeStateSMTP restart function

Ticket: 8649

Fully resets all the fields before tackling an ecapsulated message
to avoid evasion, due to the encoding of the upper file
leaking into the next one...
pull/15814/head
Philippe Antoine 2 months ago committed by Victor Julien
parent 82c4190558
commit 4985eb9dae

@ -93,6 +93,19 @@ pub struct MimeStateSMTP<'a> {
pub(crate) md5_result: String,
}
impl MimeStateSMTP<'_> {
fn restart(&mut self) {
self.state_flag = MimeSmtpParserState::MimeSmtpStart;
self.headers.truncate(self.main_headers_nb);
self.encoding = MimeSmtpEncoding::Plain;
self.decoder = None;
self.filename.clear();
self.bufeolen = 0;
self.content_type = MimeSmtpContentType::Message;
self.decoded_line.clear();
}
}
pub fn mime_smtp_state_init(
files: &mut FileContainer, sbcfg: *const StreamingBufferConfig,
) -> Option<MimeStateSMTP<'_>> {
@ -378,8 +391,8 @@ fn mime_smtp_parse_line(
ctx.main_headers_nb = ctx.headers.len();
}
if encap_msg {
ctx.state_flag = MimeSmtpParserState::MimeSmtpStart;
ctx.headers.truncate(ctx.main_headers_nb);
// looks like we have 0 headers...
ctx.restart();
return (MimeSmtpParserResult::MimeSmtpNeedsMore, warnings);
}
ctx.state_flag = MimeSmtpParserState::MimeSmtpBody;
@ -406,8 +419,7 @@ fn mime_smtp_parse_line(
ctx.main_headers_nb = ctx.headers.len();
}
if encap_msg {
ctx.state_flag = MimeSmtpParserState::MimeSmtpStart;
ctx.headers.truncate(ctx.main_headers_nb);
ctx.restart();
return (MimeSmtpParserResult::MimeSmtpNeedsMore, warnings);
}
ctx.state_flag = MimeSmtpParserState::MimeSmtpBody;
@ -461,15 +473,11 @@ fn mime_smtp_parse_line(
}
}
}
ctx.state_flag = MimeSmtpParserState::MimeSmtpStart;
let toclose = !ctx.filename.is_empty();
ctx.filename.clear();
ctx.headers.truncate(ctx.main_headers_nb);
ctx.encoding = MimeSmtpEncoding::Plain;
ctx.bufeolen = 0;
if i.len() >= b.len() + 2 && i[b.len()] == b'-' && i[b.len() + 1] == b'-' {
ctx.boundaries.pop();
}
ctx.restart();
if toclose {
return (MimeSmtpParserResult::MimeSmtpFileClose, 0);
}

Loading…
Cancel
Save