Fixed reading a line from smtp data stage

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2021-07-11 17:26:03 +02:00
parent 03c22264ea
commit 4fd0fd25c5

View File

@ -186,26 +186,33 @@ void handle_data(struct smtp_session *session, char *readbuf, int readlen, struc
puflen = read_one_line(p, '\n', puf, sizeof(puf)-1, &rc); puflen = read_one_line(p, '\n', puf, sizeof(puf)-1, &rc);
p += puflen; p += puflen;
// complete line: rc == OK and puflen > 0
// incomplete line with something in the buffer: rc == ERR and puflen > 0
if(puflen > 0){ if(puflen > 0){
// Update lasttime if we have a line to process // Update lasttime if we have a line to process
time(&(session->lasttime)); time(&(session->lasttime));
// pass the puffer to process_data() only if there was an '\n' // Save incomplete line to buffer
// on the line or the puffer does not start with a period if(rc == ERR){
if(session->protocol_state == SMTP_STATE_DATA && (rc == OK || puf[0] != '.')){ snprintf(session->buf, sizeof(session->buf)-1, "%s", puf);
session->buflen = puflen;
}
// We have a complete line to process
if(rc == OK){
if(session->protocol_state == SMTP_STATE_BDAT){
process_bdat(session, puf, puflen, cfg);
}
else if(session->protocol_state == SMTP_STATE_DATA){
sig_block(SIGALRM); sig_block(SIGALRM);
process_data(session, puf, puflen); process_data(session, puf, puflen);
sig_unblock(SIGALRM); sig_unblock(SIGALRM);
} }
else if(session->protocol_state == SMTP_STATE_BDAT){ else {
process_bdat(session, puf, puflen, cfg);
}
else if(rc == OK){
process_smtp_command(session, puf, cfg); process_smtp_command(session, puf, cfg);
} }
else {
snprintf(session->buf, MAXBUFSIZE-1, "%s", puf);
session->buflen = puflen;
} }
} }