9595/* All other commands are represented by this var */
9696#define SMTP_COMMAND_OTHER_CMD 5
9797#define SMTP_COMMAND_RSET 6
98+ #define SMTP_COMMAND_QUIT 7
9899
99100#define SMTP_DEFAULT_MAX_TX 256
100101
@@ -1080,6 +1081,11 @@ static int SMTPProcessReply(
10801081 !(state -> parser_state & SMTP_PARSER_STATE_PARSING_MULTILINE_REPLY )) {
10811082 SMTPTransactionComplete (reply_tx );
10821083 }
1084+ } else if (IsReplyToCommand (state , SMTP_COMMAND_QUIT )) {
1085+ if (reply_code == SMTP_REPLY_221 && reply_tx &&
1086+ !(state -> parser_state & SMTP_PARSER_STATE_PARSING_MULTILINE_REPLY )) {
1087+ SMTPTransactionComplete (reply_tx );
1088+ }
10831089 } else {
10841090 /* we don't care for any other command for now */
10851091 }
@@ -1276,8 +1282,9 @@ static int SMTPProcessRequest(
12761282 if (line -> len == 0 && line -> delim_len == 0 ) {
12771283 return 0 ;
12781284 }
1279- if (state -> curr_tx == NULL ||
1280- (SMTPTransactionRequestIsComplete (state -> curr_tx ) && !NoNewTx (state , line ))) {
1285+ const bool no_new_tx = NoNewTx (state , line );
1286+ if ((state -> curr_tx == NULL && (state -> tx_cnt == 0 || !no_new_tx )) ||
1287+ (SMTPTransactionRequestIsComplete (state -> curr_tx ) && !no_new_tx )) {
12811288 tx = SMTPTransactionCreate (state );
12821289 if (tx == NULL )
12831290 return -1 ;
@@ -1293,7 +1300,9 @@ static int SMTPProcessRequest(
12931300 if (frame != NULL && state -> curr_tx ) {
12941301 AppLayerFrameSetTxId (frame , state -> curr_tx -> tx_id );
12951302 }
1296- tx -> tx_data .updated_ts = true;
1303+ if (tx != NULL ) {
1304+ tx -> tx_data .updated_ts = true;
1305+ }
12971306
12981307 state -> toserver_data_count += (line -> len + line -> delim_len );
12991308
@@ -1377,6 +1386,8 @@ static int SMTPProcessRequest(
13771386 // Resets chunk index in case of connection reuse
13781387 state -> bdat_chunk_idx = 0 ;
13791388 state -> current_command = SMTP_COMMAND_RSET ;
1389+ } else if (line -> len >= 4 && SCMemcmpLowercase ("quit" , line -> buf , 4 ) == 0 ) {
1390+ state -> current_command = SMTP_COMMAND_QUIT ;
13801391 } else {
13811392 state -> current_command = SMTP_COMMAND_OTHER_CMD ;
13821393 }
@@ -2851,7 +2862,7 @@ static int SMTPParserTest02(void)
28512862 goto end ;
28522863 }
28532864 if (smtp_state -> cmds_cnt != 1 || smtp_state -> cmds_idx != 0 ||
2854- smtp_state -> cmds [0 ] != SMTP_COMMAND_OTHER_CMD ||
2865+ smtp_state -> cmds [0 ] != SMTP_COMMAND_QUIT ||
28552866 smtp_state -> parser_state != SMTP_PARSER_STATE_FIRST_REPLY_SEEN ) {
28562867 printf ("smtp parser in inconsistent state\n" );
28572868 goto end ;
@@ -3333,7 +3344,7 @@ static int SMTPParserTest05(void)
33333344 goto end ;
33343345 }
33353346 if (smtp_state -> cmds_cnt != 1 || smtp_state -> cmds_idx != 0 ||
3336- smtp_state -> cmds [0 ] != SMTP_COMMAND_OTHER_CMD ||
3347+ smtp_state -> cmds [0 ] != SMTP_COMMAND_QUIT ||
33373348 smtp_state -> parser_state !=
33383349 (SMTP_PARSER_STATE_FIRST_REPLY_SEEN | SMTP_PARSER_STATE_PIPELINING_SERVER )) {
33393350 printf ("smtp parser in inconsistent state\n" );
@@ -4356,7 +4367,7 @@ static int SMTPParserTest14(void)
43564367 goto end ;
43574368 }
43584369 if (smtp_state -> cmds_cnt != 1 || smtp_state -> cmds_idx != 0 ||
4359- smtp_state -> cmds [0 ] != SMTP_COMMAND_OTHER_CMD ||
4370+ smtp_state -> cmds [0 ] != SMTP_COMMAND_QUIT ||
43604371 smtp_state -> parser_state != SMTP_PARSER_STATE_FIRST_REPLY_SEEN ) {
43614372 printf ("smtp parser in inconsistent state l.%d\n" , __LINE__ );
43624373 goto end ;
0 commit comments