diff --git a/src/errmsg.h b/src/errmsg.h index c3de489..860f667 100644 --- a/src/errmsg.h +++ b/src/errmsg.h @@ -15,6 +15,7 @@ #define ERR_SETGID "ERR: setgid()" #define ERR_SELECT "ERR: select()" #define ERR_CHDIR "ERR: chdir() to working directory failed" +#define ERR_DAEMON "ERR: daemon()" #define ERR_OPEN_TMP_FILE "ERR: opening a tempfile" #define ERR_TIMED_OUT "ERR: timed out" #define ERR_FORK_FAILED "ERR: cannot fork()" diff --git a/src/imap.c b/src/imap.c index 354478b..c3debe2 100644 --- a/src/imap.c +++ b/src/imap.c @@ -101,7 +101,7 @@ snprintf(buf, sizeof(buf)-1, "A%d SELECT %s\r\n", *seq, folder); - n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); + write1(sd, buf, strlen(buf), use_ssl, data->ssl); if(read_response(sd, buf, sizeof(buf), seq, data, use_ssl) == 0){ trimBuffer(buf); printf("select cmd error: %s\n", buf); @@ -161,7 +161,7 @@ } - n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); + write1(sd, buf, strlen(buf), use_ssl, data->ssl); readlen = 0; nreads = 0; @@ -264,7 +264,7 @@ if(data->import->remove_after_import == 1 && dryrun == 0){ snprintf(buf, sizeof(buf)-1, "A%d STORE %d +FLAGS.SILENT (\\Deleted)\r\n", *seq, i); - n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); + write1(sd, buf, strlen(buf), use_ssl, data->ssl); read_response(sd, buf, sizeof(buf), seq, data, use_ssl); } @@ -275,12 +275,12 @@ tagoklen = strlen(tagok); snprintf(buf, sizeof(buf)-1, "A%d COPY %d %s\r\n", *seq, i, data->import->move_folder); - n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); + write1(sd, buf, strlen(buf), use_ssl, data->ssl); read_response(sd, buf, sizeof(buf), seq, data, use_ssl); if(strncmp(buf, tagok, tagoklen) == 0){ snprintf(buf, sizeof(buf)-1, "A%d STORE %d +FLAGS.SILENT (\\Deleted)\r\n", *seq, i); - n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); + write1(sd, buf, strlen(buf), use_ssl, data->ssl); read_response(sd, buf, sizeof(buf), seq, data, use_ssl); } @@ -296,7 +296,7 @@ if((data->import->remove_after_import == 1 || data->import->move_folder) && dryrun == 0){ snprintf(buf, sizeof(buf)-1, "A%d EXPUNGE\r\n", *seq); - n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); + write1(sd, buf, strlen(buf), use_ssl, data->ssl); read_response(sd, buf, sizeof(buf), seq, data, use_ssl); } @@ -351,7 +351,7 @@ } - n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); + recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); /* imap cmd: LOGIN */ diff --git a/src/parser_utils.c b/src/parser_utils.c index bc94116..5812ed7 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -220,12 +220,14 @@ if((len == 5 && (*s == '+' || *s == '-')) || (len == 8 && (strncmp(s, "GMT+", 4) == 0 || strncmp(s, "GMT-", 4) == 0))){ offset = 0; tz = strpbrk(s, "+-"); - memset(tzh, 0, 4); - memset(tzm, 0, 3); - strncpy(tzh, tz, 3); - strncpy(tzm, tz+3, 2); - offset += atoi(tzh) * 3600; - offset += atoi(tzm) * 60; + if(tz){ + memset(tzh, 0, 4); + memset(tzm, 0, 3); + strncpy(tzh, tz, 3); + strncpy(tzm, tz+3, 2); + offset += atoi(tzh) * 3600; + offset += atoi(tzm) * 60; + } continue; } @@ -351,7 +353,7 @@ if(start){ *start = '\0'; if(strlen(p) > 0){ - strncat(puf, p, sizeof(puf)-1); + strncat(puf, p, sizeof(puf)-strlen(puf)-1); } start++; @@ -386,27 +388,27 @@ } if(need_encoding == 1 && ret == OK) - strncat(puf, tmpbuf, sizeof(puf)-1); + strncat(puf, tmpbuf, sizeof(puf)-strlen(puf)-1); else - strncat(puf, s+3, sizeof(puf)-1); + strncat(puf, s+3, sizeof(puf)-strlen(puf)-1); p = end + 2; } } else { - strncat(puf, start, sizeof(puf)-1); + strncat(puf, start, sizeof(puf)-strlen(puf)-1); break; } } else { - strncat(puf, p, sizeof(puf)-1); + strncat(puf, p, sizeof(puf)-strlen(puf)-1); break; } } while(p); - if(q) strncat(puf, " ", sizeof(puf)-1); + if(q) strncat(puf, " ", sizeof(puf)-strlen(puf)-1); } while(q); @@ -450,7 +452,7 @@ if(strlen(state->miscbuf) > 0){ memset(puf, 0, sizeof(puf)); strncpy(puf, state->miscbuf, sizeof(puf)-1); - strncat(puf, buf, sizeof(puf)-1); + strncat(puf, buf, sizeof(puf)-strlen(puf)-1); memset(buf, 0, MAXBUFSIZE); memcpy(buf, puf, MAXBUFSIZE); @@ -539,7 +541,7 @@ } //printf("append last in line:*%s*, html=+%s+, j=%d\n", puf, html, j); - if(j > 0){ k += appendHTMLTag(puf, html, pos, state); } + if(j > 0){ appendHTMLTag(puf, html, pos, state); } strcpy(buf, puf); } diff --git a/src/pilerpurge.c b/src/pilerpurge.c index ba108e0..36b5699 100644 --- a/src/pilerpurge.c +++ b/src/pilerpurge.c @@ -104,7 +104,7 @@ char filename[SMALLBUFSIZE]; char *a, buf[BIGBUFSIZE-300], update_meta_sql[BIGBUFSIZE], delete_attachment_stmt[BIGBUFSIZE]; char piler_id[SMALLBUFSIZE], i[BUFLEN]; - int n=0, len, attachment_id; + int n=0, len, attachment_id=0; #ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT struct stat st; #endif @@ -149,6 +149,11 @@ while(p_fetch_results(data->stmt_select_non_referenced_attachments) == OK){ + if(strlen(piler_id) != RND_STR_LEN || attachment_id <= 0){ + printf("invalid piler_id: '%s.a%d'\n", piler_id, attachment_id); + continue; + } + snprintf(filename, sizeof(filename)-1, "%s/%02x/%c%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, cfg->server_id, piler_id[8], piler_id[9], piler_id[10], piler_id[RND_STR_LEN-4], piler_id[RND_STR_LEN-3], piler_id[RND_STR_LEN-2], piler_id[RND_STR_LEN-1], piler_id, attachment_id); #ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT if(stat(filename, &st)){ diff --git a/src/pop3.c b/src/pop3.c index 7436ba1..cbe7f65 100644 --- a/src/pop3.c +++ b/src/pop3.c @@ -75,19 +75,19 @@ } - n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); + recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); snprintf(buf, sizeof(buf)-1, "USER %s\r\n", username); write1(sd, buf, strlen(buf), use_ssl, data->ssl); - n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); + recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); snprintf(buf, sizeof(buf)-1, "PASS %s\r\n", password); write1(sd, buf, strlen(buf), use_ssl, data->ssl); - n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); + recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); if(strncmp(buf, "+OK", 3) == 0) return OK; @@ -106,9 +106,9 @@ data->import->total_messages = 0; snprintf(buf, sizeof(buf)-1, "STAT\r\n"); - n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); + write1(sd, buf, strlen(buf), use_ssl, data->ssl); - n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); + recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); if(strncmp(buf, "+OK ", 4) == 0){ p = strchr(&buf[4], ' '); @@ -140,7 +140,7 @@ return rc; } - n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); + write1(sd, buf, strlen(buf), use_ssl, data->ssl); readlen = 0; pos = 0; @@ -203,8 +203,8 @@ if(dryrun == 0 && rc == OK && data->import->remove_after_import == 1){ snprintf(buf, sizeof(buf)-1, "DELE %d\r\n", i); - n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); - n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); + write1(sd, buf, strlen(buf), use_ssl, data->ssl); + recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); } if(i % 100 == 0){ @@ -224,7 +224,7 @@ snprintf(buf, sizeof(buf)-1, "QUIT\r\n"); - n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); + write1(sd, buf, strlen(buf), use_ssl, data->ssl); if(data->quiet == 0) printf("\n"); diff --git a/src/rules.c b/src/rules.c index 5c2a9cb..7339e05 100644 --- a/src/rules.c +++ b/src/rules.c @@ -121,6 +121,8 @@ char empty = '\0'; int len; + if(rule_cond == NULL) return NULL; + if((h = malloc(sizeof(struct rule))) == NULL) return NULL; diff --git a/src/session.c b/src/session.c index 53af2b9..c39bf0b 100644 --- a/src/session.c +++ b/src/session.c @@ -300,7 +300,7 @@ if(puf[n-2] != '\r' && puf[n-1] != '\n'){ memmove(puf, puf+pos, n-pos); memset(puf+n-pos, 0, MAXBUFSIZE-n+pos); - i = recvtimeout(new_sd, buf, MAXBUFSIZE, TIMEOUT); + recvtimeout(new_sd, buf, MAXBUFSIZE, TIMEOUT); strncat(puf, buf, MAXBUFSIZE-1-n+pos); if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: partial read: %s", sdata.ttmpfile, puf); pos = 0; @@ -356,7 +356,7 @@ if(strncasecmp(buf, SMTP_CMD_HELO, strlen(SMTP_CMD_HELO)) == 0){ if(protocol_state == SMTP_STATE_INIT) protocol_state = SMTP_STATE_HELO; - strncat(resp, SMTP_RESP_250_OK, sizeof(resp)-1); + strncat(resp, SMTP_RESP_250_OK, sizeof(resp)-strlen(resp)-1); continue; } @@ -399,7 +399,7 @@ if(strncasecmp(buf, SMTP_CMD_NOOP, strlen(SMTP_CMD_NOOP)) == 0){ - strncat(resp, SMTP_RESP_250_OK, sizeof(resp)-1); + strncat(resp, SMTP_RESP_250_OK, sizeof(resp)-strlen(resp)-1); continue; } @@ -413,7 +413,7 @@ /* by default send 502 command not implemented message */ syslog(LOG_PRIORITY, "%s: invalid command: *%s*", sdata.ttmpfile, buf); - strncat(resp, SMTP_RESP_502_ERR, sizeof(resp)-1); + strncat(resp, SMTP_RESP_502_ERR, sizeof(resp)-strlen(resp)-1); } while(p); diff --git a/src/store.c b/src/store.c index 078e3db..908a35c 100644 --- a/src/store.c +++ b/src/store.c @@ -48,7 +48,7 @@ EVP_CIPHER_CTX ctx; unsigned char *outbuf=NULL; - int outlen, writelen, tmplen; + int outlen=0, writelen, tmplen; struct timezone tz; struct timeval tv1, tv2; @@ -118,7 +118,7 @@ if(p){ *p = '.'; - strncat(s, p, sizeof(s)-1); + strncat(s, p, sizeof(s)-strlen(s)-1); } @@ -131,9 +131,9 @@ p2 = strrchr(s, '/'); if(!p2) goto ENDE; *p2 = '\0'; - rc = mkdir(s, 0750); + mkdir(s, 0750); *p2 = '/'; - rc = mkdir(s, 0750); + mkdir(s, 0750); *p1 = '/'; rc = mkdir(s, 0770); if(rc == -1) syslog(LOG_PRIORITY, "%s: mkdir %s: error=%s", sdata->ttmpfile, s, strerror(errno)); } diff --git a/unit_tests/check_rules.c b/unit_tests/check_rules.c index a66b27e..3812166 100644 --- a/unit_tests/check_rules.c +++ b/unit_tests/check_rules.c @@ -132,7 +132,7 @@ unlink(sdata.tmpframe); - printf("%s, '%s'\n", rule_test[i].filename, rule); + //printf("%s, '%s'\n", rule_test[i].filename, rule); if(rule == NULL && rule == rule_test[i].expected_result) continue;