diff --git a/src/attachment.c b/src/attachment.c index 99e9432..135c9ca 100644 --- a/src/attachment.c +++ b/src/attachment.c @@ -18,7 +18,7 @@ int store_attachments(struct session_data *sdata, struct _state *state, struct __config *cfg){ uint64 id=0; - int i, found, affected_rows; + int i, rc=1, found, affected_rows; char s[SMALLBUFSIZE]; MYSQL_RES *res; MYSQL_ROW row; @@ -31,14 +31,14 @@ stmt = mysql_stmt_init(&(sdata->mysql)); if(!stmt){ if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_init() error", sdata->ttmpfile, SQL_ATTACHMENT_TABLE); - return 1; + return rc; } snprintf(s, sizeof(s)-1, "INSERT INTO %s (`piler_id`,`attachment_id`,`sig`,`name`,`type`,`size`,`ptr`) VALUES(?,?,?,?,?,?,?)", SQL_ATTACHMENT_TABLE); if(mysql_stmt_prepare(stmt, s, strlen(s))){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_prepare() error: %s", sdata->ttmpfile, SQL_ATTACHMENT_TABLE, mysql_stmt_error(stmt)); - return 1; + return rc; } @@ -68,7 +68,7 @@ if(found == 0){ if(store_file(sdata, state->attachments[i].internalname, 0, 0, cfg) == 0){ syslog(LOG_PRIORITY, "%s: error storing attachment: %s", sdata->ttmpfile, state->attachments[i].internalname); - return 1; + goto CLOSE; } } @@ -113,19 +113,19 @@ if(mysql_stmt_bind_param(stmt, bind)){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_bind_param() error: %s", sdata->ttmpfile, SQL_ATTACHMENT_TABLE, mysql_stmt_error(stmt)); - return 1; + goto CLOSE; } if(mysql_stmt_execute(stmt)){ syslog(LOG_PRIORITY, "%s attachment sql error: *%s*", sdata->ttmpfile, mysql_error(&(sdata->mysql))); - return 1; + goto CLOSE; } affected_rows = mysql_stmt_affected_rows(stmt); if(affected_rows != 1){ syslog(LOG_PRIORITY, "%s attachment sql error: affected rows: %d", sdata->ttmpfile, affected_rows); - return 1; + goto CLOSE; } } @@ -135,7 +135,12 @@ } - return 0; + rc = 0; + +CLOSE: + mysql_stmt_close(stmt); + + return rc; } @@ -169,12 +174,12 @@ if(mysql_stmt_bind_param(stmt, bind)){ - goto ENDE; + goto CLOSE; } if(mysql_stmt_execute(stmt)){ - goto ENDE; + goto CLOSE; } @@ -193,21 +198,21 @@ if(mysql_stmt_bind_result(stmt, bind)){ - goto ENDE; + goto CLOSE; } if(mysql_stmt_store_result(stmt)){ - goto ENDE; + goto CLOSE; } if(!mysql_stmt_fetch(stmt)){ if(is_null[0] == 0){ - //printf("piler id: *%s*, id: %d\n", piler_id, *id); rc = 1; } } +CLOSE: mysql_stmt_close(stmt); ENDE: @@ -249,12 +254,12 @@ len = strlen(sdata->ttmpfile); bind[0].length = &len; if(mysql_stmt_bind_param(stmt, bind)){ - goto ENDE; + goto CLOSE; } if(mysql_stmt_execute(stmt)){ - goto ENDE; + goto CLOSE; } @@ -274,13 +279,13 @@ if(mysql_stmt_bind_result(stmt, bind)){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_bind_result() error: %s", sdata->ttmpfile, SQL_METADATA_TABLE, mysql_stmt_error(stmt)); - goto ENDE; + goto CLOSE; } if(mysql_stmt_store_result(stmt)){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_store_result() error: %s", sdata->ttmpfile, SQL_METADATA_TABLE, mysql_stmt_error(stmt)); - goto ENDE; + goto CLOSE; } while(!mysql_stmt_fetch(stmt)){ @@ -291,7 +296,7 @@ rc = query_attachment_pointers(sdata, ptr, &(ptr_arr[id].piler_id[0]), &(ptr_arr[id].attachment_id), cfg); if(!rc){ attachments = -1; - goto ENDE; + goto CLOSE; } } else { @@ -303,6 +308,7 @@ } } +CLOSE: mysql_stmt_close(stmt); ENDE: diff --git a/src/defs.h b/src/defs.h index 10bc90c..772fc3d 100644 --- a/src/defs.h +++ b/src/defs.h @@ -144,7 +144,7 @@ int n_attachments; struct attachment attachments[MAX_ATTACHMENTS]; - char b_from[SMALLBUFSIZE], b_from_domain[SMALLBUFSIZE], b_to[SMALLBUFSIZE], b_to_domain[SMALLBUFSIZE], b_subject[MAXBUFSIZE], b_body[BIGBUFSIZE]; + char b_from[SMALLBUFSIZE], b_from_domain[SMALLBUFSIZE], b_to[MAXBUFSIZE], b_to_domain[SMALLBUFSIZE], b_subject[MAXBUFSIZE], b_body[BIGBUFSIZE]; }; diff --git a/src/message.c b/src/message.c index 8596d67..13e5520 100644 --- a/src/message.c +++ b/src/message.c @@ -48,13 +48,13 @@ if(mysql_stmt_bind_param(stmt, bind)){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_bind_param() error: %s", sdata->ttmpfile, SQL_METADATA_TABLE, mysql_stmt_error(stmt)); - goto ENDE; + goto CLOSE; } if(mysql_stmt_execute(stmt)){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_execute() error: %s", sdata->ttmpfile, SQL_METADATA_TABLE, mysql_stmt_error(stmt)); - goto ENDE; + goto CLOSE; } @@ -69,13 +69,13 @@ if(mysql_stmt_bind_result(stmt, bind)){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_bind_result() error: %s", sdata->ttmpfile, SQL_METADATA_TABLE, mysql_stmt_error(stmt)); - goto ENDE; + goto CLOSE; } if(mysql_stmt_store_result(stmt)){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_store_result() error: %s", sdata->ttmpfile, SQL_METADATA_TABLE, mysql_stmt_error(stmt)); - goto ENDE; + goto CLOSE; } if(!mysql_stmt_fetch(stmt)){ @@ -83,6 +83,7 @@ if(is_null[0] == 0) rc = 1; } +CLOSE: mysql_stmt_close(stmt); ENDE: @@ -113,7 +114,7 @@ int store_index_data(struct session_data *sdata, struct _state *state, uint64 id, struct __config *cfg){ - int rc; + int rc=ERR; char *subj, s[SMALLBUFSIZE]; MYSQL_STMT *stmt; @@ -127,7 +128,7 @@ stmt = mysql_stmt_init(&(sdata->mysql)); if(!stmt){ if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_init() error", sdata->ttmpfile, SQL_SPHINX_TABLE); - return ERR; + return rc; } @@ -136,7 +137,7 @@ if(mysql_stmt_prepare(stmt, s, strlen(s))){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_prepare() error: %s", sdata->ttmpfile, SQL_SPHINX_TABLE, mysql_stmt_error(stmt)); - return ERR; + return rc; } @@ -187,24 +188,27 @@ if(mysql_stmt_bind_param(stmt, bind)){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_bind_param() error: %s", sdata->ttmpfile, SQL_SPHINX_TABLE, mysql_stmt_error(stmt)); - return ERR; + goto CLOSE; } - rc = mysql_stmt_execute(stmt); - - if(rc){ + if(mysql_stmt_execute(stmt)){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_execute error: *%s*", sdata->ttmpfile, SQL_SPHINX_TABLE, mysql_error(&(sdata->mysql))); - return ERR; + goto CLOSE; } + rc = OK; - return OK; +CLOSE: + mysql_stmt_close(stmt); + + + return rc; } int store_recipients(struct session_data *sdata, char *to, uint64 id, struct __config *cfg){ - int rc, ret=OK; + int ret=OK; char *p, *q, s[SMALLBUFSIZE], puf[SMALLBUFSIZE]; MYSQL_STMT *stmt; @@ -247,13 +251,12 @@ if(mysql_stmt_bind_param(stmt, bind)){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_bind_param() error: %s", sdata->ttmpfile, SQL_RECIPIENT_TABLE, mysql_stmt_error(stmt)); - return ERR; + ret = ERR; + goto CLOSE; } - rc = mysql_stmt_execute(stmt); - - if(rc){ + if(mysql_stmt_execute(stmt)){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_execute error: *%s*", sdata->ttmpfile, SQL_RECIPIENT_TABLE, mysql_error(&(sdata->mysql))); ret = ERR; } @@ -265,6 +268,10 @@ } while(p); + +CLOSE: + mysql_stmt_close(stmt); + return ret; } @@ -336,7 +343,7 @@ if(mysql_stmt_bind_param(stmt, bind)){ syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_bind_param() error: %s", sdata->ttmpfile, SQL_METADATA_TABLE, mysql_stmt_error(stmt)); - return ERR; + goto CLOSE; } @@ -366,6 +373,9 @@ } } +CLOSE: + mysql_stmt_close(stmt); + return ret; } diff --git a/src/parser.c b/src/parser.c index 8734677..e900ed4 100644 --- a/src/parser.c +++ b/src/parser.c @@ -411,7 +411,7 @@ if(is_email_address_on_my_domains(puf, cfg) == 1) sdata->internal_sender = 1; } - else if((state->message_state == MSG_TO || state->message_state == MSG_CC) && state->is_1st_header == 1 && does_it_seem_like_an_email_address(puf) == 1 && strlen(state->b_to) < SMALLBUFSIZE-len-1){ + else if((state->message_state == MSG_TO || state->message_state == MSG_CC) && state->is_1st_header == 1 && does_it_seem_like_an_email_address(puf) == 1 && strlen(state->b_to) < MAXBUFSIZE-len-1){ if(is_string_on_list(state->rcpt, puf) == 0){ append_list(&(state->rcpt), puf); diff --git a/src/parser_utils.c b/src/parser_utils.c index 66d8740..a27eec6 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -76,7 +76,7 @@ memset(state->b_from, 0, SMALLBUFSIZE); memset(state->b_from_domain, 0, SMALLBUFSIZE); - memset(state->b_to, 0, SMALLBUFSIZE); + memset(state->b_to, 0, MAXBUFSIZE); memset(state->b_to_domain, 0, SMALLBUFSIZE); memset(state->b_subject, 0, MAXBUFSIZE); memset(state->b_body, 0, BIGBUFSIZE); diff --git a/src/pilerget.c b/src/pilerget.c index c76c453..95e15ca 100644 --- a/src/pilerget.c +++ b/src/pilerget.c @@ -48,12 +48,12 @@ if(mysql_stmt_bind_param(stmt, bind)){ - goto ENDE; + goto CLOSE; } if(mysql_stmt_execute(stmt)){ - goto ENDE; + goto CLOSE; } @@ -77,16 +77,18 @@ bind[2].length = &len; if(mysql_stmt_bind_result(stmt, bind)){ - goto ENDE; + goto CLOSE; } if(mysql_stmt_store_result(stmt)){ - goto ENDE; + goto CLOSE; } mysql_stmt_fetch(stmt); + +CLOSE: mysql_stmt_close(stmt); ENDE: