From c918ad2a6679ff3565a484412454727120c2645d Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Sat, 17 Mar 2018 17:32:32 +0100 Subject: [PATCH] fix handling partial lines in DATA stage Signed-off-by: Janos SUTO --- src/defs.h | 1 + src/piler-smtp.c | 5 +++-- src/session.c | 2 ++ src/smtp.c | 6 +++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/defs.h b/src/defs.h index 129c56b7..8ab32905 100644 --- a/src/defs.h +++ b/src/defs.h @@ -391,6 +391,7 @@ struct smtp_session { int fd; int bad; int buflen; + int last_data_char; int tot_len; int bdat_rounds; int bdat_last_round; diff --git a/src/piler-smtp.c b/src/piler-smtp.c index 77bd7d66..8d232d4c 100644 --- a/src/piler-smtp.c +++ b/src/piler-smtp.c @@ -55,7 +55,7 @@ void usage(){ void p_clean_exit(int sig){ 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); @@ -190,10 +190,11 @@ int main(int argc, char **argv){ set_signal_handler(SIGINT, p_clean_exit); set_signal_handler(SIGTERM, p_clean_exit); - set_signal_handler(SIGKILL, 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(SIGHUP, initialise_configuration); diff --git a/src/session.c b/src/session.c index d5b73d0e..7e72ba4f 100644 --- a/src/session.c +++ b/src/session.c @@ -119,6 +119,8 @@ void init_smtp_session(struct smtp_session *session, int slot, int sd, struct co session->net.ctx = NULL; session->net.ssl = NULL; + session->last_data_char = 0; + session->fd = -1; memset(session->mailfrom, 0, SMALLBUFSIZE); diff --git a/src/smtp.c b/src/smtp.c index 171e789e..e8c89384 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -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){ - if(strcmp(buf, ".\r\n") == 0){ + if(session->last_data_char == '\n' && strcmp(buf, ".\r\n") == 0){ process_command_period(session); } 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); } + + 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); session->buflen = 0; + session->last_data_char = 0; memset(session->buf, 0, SMALLBUFSIZE); send_smtp_response(session, buf); @@ -301,6 +304,7 @@ void process_command_reset(struct smtp_session *session){ session->tot_len = 0; session->fd = -1; session->protocol_state = SMTP_STATE_HELO; + session->last_data_char = 0; reset_bdat_counters(session);