Added debugging to track piler-smtp segfault issue

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2021-02-10 21:10:35 +01:00
parent 6716bec68c
commit 9856b92c22
3 changed files with 19 additions and 11 deletions

View File

@ -94,7 +94,7 @@ void check_for_client_timeout(){
for(int i=0; i<cfg.max_connections; i++){ for(int i=0; i<cfg.max_connections; i++){
if(sessions[i] && now - sessions[i]->lasttime >= cfg.smtp_timeout){ if(sessions[i] && now - sessions[i]->lasttime >= cfg.smtp_timeout){
syslog(LOG_PRIORITY, "client %s timeout, lasttime: %ld", sessions[i]->remote_host, sessions[i]->lasttime); syslog(LOG_PRIORITY, "client %s timeout, lasttime: %ld", sessions[i]->remote_host, sessions[i]->lasttime);
tear_down_session(sessions, sessions[i]->slot, &num_connections); tear_down_session(sessions, sessions[i]->slot, &num_connections, "timeout");
} }
} }
} }
@ -232,7 +232,7 @@ int main(int argc, char **argv){
if(cfg.verbosity >= _LOG_EXTREME) syslog(LOG_PRIORITY, "ERROR: the remote end hung up without sending QUIT"); if(cfg.verbosity >= _LOG_EXTREME) syslog(LOG_PRIORITY, "ERROR: the remote end hung up without sending QUIT");
session = get_session_by_socket(sessions, cfg.max_connections, events[i].data.fd); session = get_session_by_socket(sessions, cfg.max_connections, events[i].data.fd);
if(session) if(session)
tear_down_session(sessions, session->slot, &num_connections); tear_down_session(sessions, session->slot, &num_connections, "hungup");
else else
close(events[i].data.fd); close(events[i].data.fd);
continue; continue;
@ -333,7 +333,7 @@ int main(int argc, char **argv){
/* Don't wait until the remote client closes the connection after he sent the QUIT command */ /* Don't wait until the remote client closes the connection after he sent the QUIT command */
if(done || session->protocol_state == SMTP_STATE_FINISHED){ if(done || session->protocol_state == SMTP_STATE_FINISHED){
tear_down_session(sessions, session->slot, &num_connections); tear_down_session(sessions, session->slot, &num_connections, "done");
} }
} }

View File

@ -70,7 +70,7 @@ void load_mydomains(struct session_data *sdata, struct data *data, struct config
int is_email_address_on_my_domains(char *email, struct data *data); int is_email_address_on_my_domains(char *email, struct data *data);
int start_new_session(struct smtp_session **sessions, int socket, int *num_connections, struct smtp_acl *smtp_acl[], char *client_addr, struct config *cfg); int start_new_session(struct smtp_session **sessions, int socket, int *num_connections, struct smtp_acl *smtp_acl[], char *client_addr, struct config *cfg);
void tear_down_session(struct smtp_session **sessions, int slot, int *num_connections); void tear_down_session(struct smtp_session **sessions, int slot, int *num_connections, char *reason);
struct smtp_session *get_session_by_socket(struct smtp_session **sessions, int max_connections, int socket); struct smtp_session *get_session_by_socket(struct smtp_session **sessions, int max_connections, int socket);
void write_envelope_addresses(struct smtp_session *session, struct config *cfg); void write_envelope_addresses(struct smtp_session *session, struct config *cfg);
void handle_data(struct smtp_session *session, char *readbuf, int readlen, struct config *cfg); void handle_data(struct smtp_session *session, char *readbuf, int readlen, struct config *cfg);

View File

@ -118,28 +118,38 @@ void init_smtp_session(struct smtp_session *session, int slot, int sd, char *cli
void free_smtp_session(struct smtp_session *session){ void free_smtp_session(struct smtp_session *session){
if(session){ if(session){
syslog(LOG_PRIORITY, "free_smtp_session()");
if(session->net.use_ssl == 1){ if(session->net.use_ssl == 1){
syslog(LOG_PRIORITY, "SSL_shutdown()");
SSL_shutdown(session->net.ssl); SSL_shutdown(session->net.ssl);
SSL_free(session->net.ssl); SSL_free(session->net.ssl);
syslog(LOG_PRIORITY, "SSL_free()");
} }
if(session->net.ctx) SSL_CTX_free(session->net.ctx); if(session->net.ctx){
syslog(LOG_PRIORITY, "SSL_CTX_free");
SSL_CTX_free(session->net.ctx);
}
syslog(LOG_PRIORITY, "freeing session");
free(session); free(session);
syslog(LOG_PRIORITY, "free(session) done");
} }
} }
void tear_down_session(struct smtp_session **sessions, int slot, int *num_connections){ void tear_down_session(struct smtp_session **sessions, int slot, int *num_connections, char *reason){
if(sessions[slot] == NULL){ if(sessions[slot] == NULL){
syslog(LOG_PRIORITY, "session already torn down, slot=%d (%d active connections)", slot, *num_connections); syslog(LOG_PRIORITY, "session already torn down, slot=%d, reason=%s (%d active connections)", slot, reason, *num_connections);
return; return;
} }
syslog(LOG_PRIORITY, "disconnected from %s on fd=%d, slot=%d (%d active connections)", sessions[slot]->remote_host, sessions[slot]->net.socket, slot, (*num_connections)-1); if(*num_connections > 0) (*num_connections)--;
syslog(LOG_PRIORITY, "disconnected from %s on fd=%d, slot=%d, reason=%s (%d active connections)",
sessions[slot]->remote_host, sessions[slot]->net.socket, slot, reason, *num_connections);
close(sessions[slot]->net.socket); close(sessions[slot]->net.socket);
@ -152,8 +162,6 @@ void tear_down_session(struct smtp_session **sessions, int slot, int *num_connec
free_smtp_session(sessions[slot]); free_smtp_session(sessions[slot]);
sessions[slot] = NULL; sessions[slot] = NULL;
if(*num_connections > 0) (*num_connections)--;
} }