Skip to content

Commit e4d7d16

Browse files
committed
smtp: treat a mid-session helo/ehlo like a rset
A HELO or EHLO issued later in the session must clear all buffers and reset the state exactly as if a RSET had been issued (RFC 5321 4.1.4). Instead it was ignored, merging the next envelope into the abandoned one and attributing the delivered message to the abandoned sender. Handle a HELO/EHLO arriving after an envelope has been started or a DATA/BDAT has been attempted like a RSET, completing the transaction on the server's 250 reply. The data-phase check matters for a rejected envelope-less DATA: its stale state would otherwise leave the next message body unparsed. Ticket: OISF#8715
1 parent 0fbec65 commit e4d7d16

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/app-layer-smtp.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,17 @@ static int SMTPProcessRequest(
14141414
if (r == -1) {
14151415
SCReturnInt(-1);
14161416
}
1417-
state->current_command = SMTP_COMMAND_OTHER_CMD;
1417+
if (state->curr_tx->mail_from != NULL || !TAILQ_EMPTY(&state->curr_tx->rcpt_to_list) ||
1418+
state->curr_tx->progress_ts != SMTP_REQUEST_STARTED) {
1419+
/* Mid-session HELO/EHLO resets the state as if a RSET
1420+
* had been issued (RFC 5321 4.1.4). The progress check
1421+
* catches a transaction with no envelope but an attempted
1422+
* DATA or BDAT, such as a rejected envelope-less DATA. */
1423+
state->bdat_chunk_idx = 0;
1424+
state->current_command = SMTP_COMMAND_RSET;
1425+
} else {
1426+
state->current_command = SMTP_COMMAND_OTHER_CMD;
1427+
}
14181428
} else if (line->len >= 9 && SCMemcmpLowercase("mail from", line->buf, 9) == 0) {
14191429
r = SMTPParseCommandMAILFROM(state, line);
14201430
if (r == -1) {

0 commit comments

Comments
 (0)