9595/* All other commands are represented by this var */
9696#define SMTP_COMMAND_OTHER_CMD 5
9797#define SMTP_COMMAND_RSET 6
98+ /* Like SMTP_COMMAND_BDAT, but the chunk was flagged LAST, so the server
99+ * reply matched to this command is the final verdict for the
100+ * transaction */
101+ #define SMTP_COMMAND_BDAT_LAST 7
98102
99103#define SMTP_DEFAULT_MAX_TX 256
100104
@@ -990,6 +994,7 @@ static int SMTPProcessReply(
990994 }
991995 if (state -> curr_tx ) {
992996 SMTPTransactionComplete (state );
997+ SMTPSetProgressTC (state -> curr_tx , SMTP_RESPONSE_COMPLETE );
993998 }
994999 } else {
9951000 /* decoder event */
@@ -1010,10 +1015,19 @@ static int SMTPProcessReply(
10101015 }
10111016 } else if (IsReplyToCommand (state , SMTP_COMMAND_BDAT )) {
10121017 SMTPSetProgressTC (state -> curr_tx , SMTP_RESPONSE_DATA );
1018+ } else if (IsReplyToCommand (state , SMTP_COMMAND_BDAT_LAST )) {
1019+ /* the reply to the BDAT LAST chunk is the server's verdict on
1020+ * the transaction */
1021+ SMTPSetProgressTC (state -> curr_tx , SMTP_RESPONSE_COMPLETE );
1022+ } else if (IsReplyToCommand (state , SMTP_COMMAND_DATA_MODE )) {
1023+ /* the reply to the mail data is the server's verdict on the
1024+ * transaction */
1025+ SMTPSetProgressTC (state -> curr_tx , SMTP_RESPONSE_COMPLETE );
10131026 } else if (IsReplyToCommand (state , SMTP_COMMAND_RSET )) {
10141027 if (reply_code == SMTP_REPLY_250 && state -> curr_tx &&
10151028 !(state -> parser_state & SMTP_PARSER_STATE_PARSING_MULTILINE_REPLY )) {
10161029 SMTPTransactionComplete (state );
1030+ SMTPSetProgressTC (state -> curr_tx , SMTP_RESPONSE_COMPLETE );
10171031 }
10181032 } else {
10191033 /* we don't care for any other command for now */
@@ -1308,7 +1322,11 @@ static int SMTPProcessRequest(
13081322 if (r == -1 ) {
13091323 SCReturnInt (-1 );
13101324 }
1311- state -> current_command = SMTP_COMMAND_BDAT ;
1325+ if (state -> bdat_last ) {
1326+ state -> current_command = SMTP_COMMAND_BDAT_LAST ;
1327+ } else {
1328+ state -> current_command = SMTP_COMMAND_BDAT ;
1329+ }
13121330 SMTPSetProgressTS (tx , SMTP_REQUEST_DATA );
13131331 if (state -> bdat_chunk_len == 0 ) {
13141332 state -> parser_state &= ~SMTP_PARSER_STATE_COMMAND_DATA_MODE ;
@@ -1360,6 +1378,7 @@ static int SMTPProcessRequest(
13601378 return SMTPProcessCommandDATA (state , tx , f , line );
13611379
13621380 case SMTP_COMMAND_BDAT :
1381+ case SMTP_COMMAND_BDAT_LAST :
13631382 return SMTPProcessCommandBDAT (state , line );
13641383
13651384 default :
@@ -1496,7 +1515,8 @@ static AppLayerResult SMTPParse(uint8_t direction, Flow *f, SMTPState *state,
14961515 /* toserver */
14971516 if (direction == 0 ) {
14981517 if (((state -> current_command == SMTP_COMMAND_DATA ) ||
1499- (state -> current_command == SMTP_COMMAND_BDAT )) &&
1518+ (state -> current_command == SMTP_COMMAND_BDAT ) ||
1519+ (state -> current_command == SMTP_COMMAND_BDAT_LAST )) &&
15001520 (state -> parser_state & SMTP_PARSER_STATE_COMMAND_DATA_MODE )) {
15011521 int ret = SMTPPreProcessCommands (state , f , & stream_slice , & input , & line );
15021522 DEBUG_VALIDATE_BUG_ON (ret != 0 && ret != -1 && ret != 1 );
@@ -1896,7 +1916,7 @@ static int SMTPStateGetAlstateProgress(void *vtx, uint8_t direction)
18961916 SMTPTransaction * tx = vtx ;
18971917 if (direction & STREAM_TOSERVER )
18981918 return tx -> done ? SMTP_REQUEST_COMPLETE : tx -> progress_ts ;
1899- return tx -> done ? SMTP_RESPONSE_COMPLETE : tx -> progress_tc ;
1919+ return tx -> progress_tc ;
19001920}
19011921
19021922static AppLayerGetFileState SMTPGetTxFiles (void * txv , uint8_t direction )
0 commit comments