fix handling partial lines in DATA stage

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2018-03-17 17:32:32 +01:00
parent f2853b9f18
commit c918ad2a66
4 changed files with 11 additions and 3 deletions

View File

@ -391,6 +391,7 @@ struct smtp_session {
int fd; int fd;
int bad; int bad;
int buflen; int buflen;
int last_data_char;
int tot_len; int tot_len;
int bdat_rounds; int bdat_rounds;
int bdat_last_round; int bdat_last_round;

View File

@ -55,7 +55,7 @@ void usage(){
void p_clean_exit(int sig){ void p_clean_exit(int sig){
int i; int i;
syslog(LOG_PRIORITY, "got signal: %d, %s", sig, strsignal(sig)); if(sig > 0) syslog(LOG_PRIORITY, "got signal: %d, %s", sig, strsignal(sig));
if(listenerfd != -1) close(listenerfd); if(listenerfd != -1) close(listenerfd);
@ -190,10 +190,11 @@ int main(int argc, char **argv){
set_signal_handler(SIGINT, p_clean_exit); set_signal_handler(SIGINT, p_clean_exit);
set_signal_handler(SIGTERM, p_clean_exit); set_signal_handler(SIGTERM, p_clean_exit);
set_signal_handler(SIGKILL, p_clean_exit); set_signal_handler(SIGKILL, p_clean_exit);
set_signal_handler(SIGSEGV, p_clean_exit); set_signal_handler(SIGSEGV, p_clean_exit);
set_signal_handler(SIGPIPE, SIG_IGN);
set_signal_handler(SIGALRM, check_for_client_timeout); set_signal_handler(SIGALRM, check_for_client_timeout);
set_signal_handler(SIGHUP, initialise_configuration); set_signal_handler(SIGHUP, initialise_configuration);

View File

@ -119,6 +119,8 @@ void init_smtp_session(struct smtp_session *session, int slot, int sd, struct co
session->net.ctx = NULL; session->net.ctx = NULL;
session->net.ssl = NULL; session->net.ssl = NULL;
session->last_data_char = 0;
session->fd = -1; session->fd = -1;
memset(session->mailfrom, 0, SMALLBUFSIZE); memset(session->mailfrom, 0, SMALLBUFSIZE);

View File

@ -71,7 +71,7 @@ void process_smtp_command(struct smtp_session *session, char *buf, struct config
void process_data(struct smtp_session *session, char *buf, int buflen){ void process_data(struct smtp_session *session, char *buf, int buflen){
if(strcmp(buf, ".\r\n") == 0){ if(session->last_data_char == '\n' && strcmp(buf, ".\r\n") == 0){
process_command_period(session); process_command_period(session);
} }
else { else {
@ -81,6 +81,8 @@ void process_data(struct smtp_session *session, char *buf, int buflen){
} }
else syslog(LOG_PRIORITY, "ERROR (line: %d) process_data(): failed to write %d bytes", __LINE__, buflen); else syslog(LOG_PRIORITY, "ERROR (line: %d) process_data(): failed to write %d bytes", __LINE__, buflen);
} }
session->last_data_char = buf[buflen-1];
} }
@ -280,6 +282,7 @@ void process_command_period(struct smtp_session *session){
snprintf(buf, sizeof(buf)-1, "250 OK <%s>\r\n", session->ttmpfile); snprintf(buf, sizeof(buf)-1, "250 OK <%s>\r\n", session->ttmpfile);
session->buflen = 0; session->buflen = 0;
session->last_data_char = 0;
memset(session->buf, 0, SMALLBUFSIZE); memset(session->buf, 0, SMALLBUFSIZE);
send_smtp_response(session, buf); send_smtp_response(session, buf);
@ -301,6 +304,7 @@ void process_command_reset(struct smtp_session *session){
session->tot_len = 0; session->tot_len = 0;
session->fd = -1; session->fd = -1;
session->protocol_state = SMTP_STATE_HELO; session->protocol_state = SMTP_STATE_HELO;
session->last_data_char = 0;
reset_bdat_counters(session); reset_bdat_counters(session);