diff --git a/configure b/configure index 639223d5..19428bde 100755 --- a/configure +++ b/configure @@ -4854,7 +4854,7 @@ echo; echo CFLAGS="$static -std=c99 -O2 -fPIC -Wall -Wextra -Wuninitialized -Wno-format-truncation -g" LIBS="$antispam_libs $sunos_libs " -OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o bdat.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o imap.o pop3.o extract.o mydomains.o tokenizer.o $objs" +OBJS="dirs.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o bdat.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o imap.o pop3.o extract.o mydomains.o tokenizer.o $objs" ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile systemd/Makefile unit_tests/Makefile webui/Makefile contrib/imap/Makefile" diff --git a/configure.in b/configure.in index 388ac8e7..34bbebcc 100644 --- a/configure.in +++ b/configure.in @@ -537,7 +537,7 @@ echo; echo CFLAGS="$static -std=c99 -O2 -fPIC -Wall -Wextra -Wuninitialized -Wno-format-truncation -g" LIBS="$antispam_libs $sunos_libs " -OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o bdat.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o imap.o pop3.o extract.o mydomains.o tokenizer.o $objs" +OBJS="dirs.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o bdat.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o imap.o pop3.o extract.o mydomains.o tokenizer.o $objs" AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile systemd/Makefile unit_tests/Makefile webui/Makefile contrib/imap/Makefile]) AC_OUTPUT diff --git a/cppcheck.sh b/cppcheck.sh new file mode 100755 index 00000000..88794857 --- /dev/null +++ b/cppcheck.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -o nounset +set -o errexit +set -o pipefail + +cppcheck -DHAVE_PDFTOTEXT -DHAVE_PPTHTML -DHAVE_TNEF -DHAVE_UNRTF -DHAVE_XLS2CSV -DHAVE_CATPPT -DHAVE_CATDOC -DHAVE_ZIP -D_GNU_SOURCE -DHAVE_DAEMON -DHAVE_TRE -DHAVE_CLAMD -DHAVE_LIBCLAMAV -DNEED_MYSQL --error-exitcode=1 --enable=all --suppressions-list=suppressions.txt --force src/ unit_tests/ diff --git a/src/archive.c b/src/archive.c index 9a0ffe97..9984c26f 100644 --- a/src/archive.c +++ b/src/archive.c @@ -54,7 +54,6 @@ void zerr(int ret){ int inf(unsigned char *in, int len, int mode, char **buffer, FILE *dest){ int ret, pos=0; - unsigned have; z_stream strm; char *new_ptr; unsigned char out[REALLYBIGBUFSIZE]; @@ -96,7 +95,7 @@ int inf(unsigned char *in, int len, int mode, char **buffer, FILE *dest){ return ret; } - have = REALLYBIGBUFSIZE - strm.avail_out; + unsigned have = REALLYBIGBUFSIZE - strm.avail_out; /* * write the uncompressed result either to stdout @@ -235,8 +234,8 @@ CLEANUP: int retrieve_email_from_archive(struct session_data *sdata, FILE *dest, struct config *cfg){ - int i, attachments; - char *buffer=NULL, *saved_buffer, *p, filename[SMALLBUFSIZE], pointer[SMALLBUFSIZE]; + int attachments; + char *buffer=NULL, *saved_buffer, *p, filename[SMALLBUFSIZE]; struct ptr_array ptr_arr[MAX_ATTACHMENTS]; #ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT struct stat st; @@ -270,7 +269,8 @@ int retrieve_email_from_archive(struct session_data *sdata, FILE *dest, struct c if(buffer){ saved_buffer = buffer; - for(i=1; i<=attachments; i++){ + for(int i=1; i<=attachments; i++){ + char pointer[SMALLBUFSIZE]; snprintf(pointer, sizeof(pointer)-1, "ATTACHMENT_POINTER_%s.a%d_XXX_PILER", sdata->ttmpfile, i); p = strstr(buffer, pointer); diff --git a/src/attachment.c b/src/attachment.c index 70a156b6..f6d14f5d 100644 --- a/src/attachment.c +++ b/src/attachment.c @@ -17,7 +17,6 @@ int store_attachments(struct session_data *sdata, struct parser_state *state, struct config *cfg){ - uint64 id=0; int i, rc=1, found, affected_rows; struct sql sql, sql2; @@ -27,7 +26,7 @@ int store_attachments(struct session_data *sdata, struct parser_state *state, st for(i=1; i<=state->n_attachments; i++){ found = 0; - id = 0; + uint64 id = 0; if(state->attachments[i].size > 0){ diff --git a/src/base64.c b/src/base64.c deleted file mode 100644 index 82e69ff2..00000000 --- a/src/base64.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * base64.c, SJ - */ - -#include -#include - - -char base64_value(char c){ - static const char *base64_table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - if((int)c > 63) return '='; - - return base64_table[(int)c]; -} - - -void base64_encode_block(unsigned char *in, int inlen, char *out){ - char a, b, c, d, fragment; - - sprintf(out, "===="); - - if(inlen <= 0) return; - - fragment = *in & 0x3; - - a = *in >> 2; - - out[0] = base64_value(a); - - b = fragment << 4; - - if(inlen > 1) - b += *(in+1) >> 4; - - out[1] = base64_value(b); - - if(inlen == 1) return; - - - c = *(in+1) & 0xf; - c = c << 2; - - if(inlen > 2){ - fragment = *(in+2) & 0xfc; - c += fragment >> 6; - - d = *(in+2) & 0x3f; - out[3] = base64_value(d); - } - - out[2] = base64_value(c); -} - - -void base64_encode(unsigned char *in, int inlen, char *out, int outlen){ - int i=0, j, pos=0; - unsigned char buf[3]; - - memset(buf, 0, 3); - memset(out, 0, outlen); - - for(j=0; jfd == -1){ @@ -106,6 +104,7 @@ void process_bdat(struct smtp_session *session, char *readbuf, int readlen, stru move_email(session); + char buf[SMALLBUFSIZE]; snprintf(buf, sizeof(buf)-1, "250 OK <%s>\r\n", session->ttmpfile); send_smtp_response(session, buf); syslog(LOG_PRIORITY, "received: %s, from=%s, size=%d, client=%s, fd=%d", session->ttmpfile, session->mailfrom, session->tot_len, session->remote_host, session->net.socket); diff --git a/src/cfg.c b/src/cfg.c index 820e5cd9..0c40b705 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -17,31 +17,12 @@ int string_parser(char *src, char *target, int limit){ return 0; }; -int multi_line_string_parser(char *src, char *target, unsigned int limit){ - if(strlen(src) > 0 && strlen(target) + strlen(src) + 3 < limit){ - strncat(target, src, limit-strlen(target)); - strncat(target, "\r\n", limit-strlen(target)); - - return 0; - } - - return 1; -}; - int int_parser(char *src, int *target){ *target = strtol(src, (char **) NULL, 10); return 0; }; - -int float_parser(char *src, float *target){ - *target = strtof(src, (char **) NULL); - - return 0; -}; - - struct _parse_rule { char *name; char *type; diff --git a/src/clamd.c b/src/clamd.c index 8f7f3f08..07b4a15b 100644 --- a/src/clamd.c +++ b/src/clamd.c @@ -20,7 +20,7 @@ int clamd_scan(char *tmpfile, struct config *cfg){ int s, n; - char *p, *q, buf[MAXBUFSIZE], scan_cmd[SMALLBUFSIZE]; + char buf[MAXBUFSIZE], scan_cmd[SMALLBUFSIZE]; struct sockaddr_un server; chmod(tmpfile, 0644); @@ -58,9 +58,9 @@ int clamd_scan(char *tmpfile, struct config *cfg){ if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: CLAMD DEBUG: %d %s", tmpfile, n, buf); if(strcasestr(buf, CLAMD_RESP_INFECTED)){ - p = strchr(buf, ' '); + char *p = strchr(buf, ' '); if(p){ - q = strrchr(p, ' '); + char *q = strrchr(p, ' '); if(q){ *q = '\0'; p++; diff --git a/src/counters.c b/src/counters.c index 35ad9402..f7030b30 100644 --- a/src/counters.c +++ b/src/counters.c @@ -51,13 +51,12 @@ struct counters load_counters(struct session_data *sdata){ void update_counters(struct session_data *sdata, struct data *data, struct counters *counters, struct config *cfg){ char buf[MAXBUFSIZE]; #ifdef HAVE_MEMCACHED - unsigned long long mc, rcvd; + unsigned long long mc; struct counters c; - char key[MAX_MEMCACHED_KEY_LEN]; unsigned int flags=0; #endif - if(counters->c_virus + counters->c_duplicate + counters->c_ignore + counters->c_size + counters->c_stored_size <= 0) return; + if(counters->c_virus + counters->c_duplicate + counters->c_ignore + counters->c_size + counters->c_stored_size == 0) return; #ifdef HAVE_MEMCACHED if(cfg->update_counters_to_memcached == 1){ @@ -65,7 +64,7 @@ void update_counters(struct session_data *sdata, struct data *data, struct count /* increment counters to memcached */ if(memcached_increment(&(data->memc), MEMCACHED_MSGS_RCVD, counters->c_rcvd, &mc) == MEMCACHED_SUCCESS){ - rcvd = mc; + unsigned long long rcvd = mc; if(counters->c_virus > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_VIRUS, counters->c_virus, &mc); if(counters->c_duplicate > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_DUPLICATE, counters->c_duplicate, &mc); @@ -79,6 +78,8 @@ void update_counters(struct session_data *sdata, struct data *data, struct count snprintf(buf, MAXBUFSIZE-1, "%s %s %s %s %s %s %s", MEMCACHED_MSGS_RCVD, MEMCACHED_MSGS_VIRUS, MEMCACHED_MSGS_DUPLICATE, MEMCACHED_MSGS_IGNORE, MEMCACHED_MSGS_SIZE, MEMCACHED_MSGS_STORED_SIZE, MEMCACHED_COUNTERS_LAST_UPDATE); if(memcached_mget(&(data->memc), buf) == MEMCACHED_SUCCESS){ + char key[MAX_MEMCACHED_KEY_LEN]; + while((memcached_fetch_result(&(data->memc), &key[0], &buf[0], &flags))){ if(!strcmp(key, MEMCACHED_MSGS_RCVD)) c.c_rcvd = strtoull(buf, NULL, 10); else if(!strcmp(key, MEMCACHED_MSGS_VIRUS)) c.c_virus = strtoull(buf, NULL, 10); diff --git a/src/decoder.c b/src/decoder.c index 93c4fcc7..fc034ff1 100644 --- a/src/decoder.c +++ b/src/decoder.c @@ -98,20 +98,6 @@ inline void utf8_encode_char(unsigned char c, unsigned char *buf, int buflen, in } -void sanitiseBase64(char *s){ - char *p1; - - if(s == NULL) return; - - for(; *s; s++){ - if(b64[(unsigned int)(*s & 0xFF)] == 255){ - for(p1 = s; p1[0] != '\0'; p1++) - p1[0] = p1[1]; - } - } -} - - inline static void pack_4_into_3(char *s, char *s2){ int j, n[4], k1, k2; @@ -157,7 +143,7 @@ int decodeBase64(char *p){ int decode_base64_to_buffer(char *p, int plen, unsigned char *b, int blen){ - int i, len=0, decodedlen; + int i, len=0; char s[5], s2[3]; if(plen < 4 || plen > blen) @@ -166,7 +152,7 @@ int decode_base64_to_buffer(char *p, int plen, unsigned char *b, int blen){ for(i=0; iimport->filename, '/'); if(p) p++; else p = data->import->filename; + char newpath[SMALLBUFSIZE]; snprintf(newpath, sizeof(newpath)-2, "%s/%s", data->import->failed_folder, p); if(rename(data->import->filename, newpath)) diff --git a/src/import_imap.c b/src/import_imap.c index 79876c74..7804767e 100644 --- a/src/import_imap.c +++ b/src/import_imap.c @@ -73,7 +73,7 @@ int import_from_imap_server(struct session_data *sdata, struct data *data, struc q = data->imapfolders[i]; while(q != NULL){ - if(q && q->str && strlen(q->str) > 1){ + if(q->str && strlen(q->str) > 1){ skipmatch = 0; diff --git a/src/list.c b/src/list.c deleted file mode 100644 index 965d48b3..00000000 --- a/src/list.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * list.c, SJ - */ - -#include -#include -#include -#include -#include "list.h" -#include "config.h" - - -int append_list(struct list **list, char *p){ - struct list *q, *t, *u=NULL; - - q = *list; - - while(q){ - if(strcmp(q->s, p) == 0) - return 0; - - u = q; - q = q->r; - } - - t = create_list_item(p); - if(t){ - if(*list == NULL) - *list = t; - else if(u) - u->r = t; - - return 1; - } - - return -1; -} - - -struct list *create_list_item(char *s){ - struct list *h=NULL; - - if((h = malloc(sizeof(struct list))) == NULL) - return NULL; - - snprintf(h->s, SMALLBUFSIZE-1, "%s", s); - h->r = NULL; - - return h; -} - - -int is_string_on_list(struct list *list, char *s){ - struct list *p; - - p = list; - - while(p != NULL){ - if(strcmp(p->s, s) == 0) return 1; - p = p->r; - } - - return 0; -} - - -int is_item_on_string(struct list *list, char *s){ - struct list *p; - - p = list; - - while(p != NULL){ - if(strstr(s, p->s)) return 1; - p = p->r; - } - - return 0; -} - - -void free_list(struct list *list){ - struct list *p, *q; - - p = list; - - while(p != NULL){ - q = p->r; - - if(p) - free(p); - - p = q; - } -} diff --git a/src/list.h b/src/list.h deleted file mode 100644 index 56a413c7..00000000 --- a/src/list.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * list.h, SJ - */ - -#ifndef _LIST_H - #define _LIST_H - -#include "defs.h" - -int append_list(struct list **list, char *p); -struct list *create_list_item(char *s); -int is_string_on_list(struct list *list, char *s); -int is_item_on_string(struct list *list, char *s); -void free_list(struct list *list); - -#endif /* _LIST_H */ diff --git a/src/memc.c b/src/memc.c index c56c4db8..c04b84a0 100644 --- a/src/memc.c +++ b/src/memc.c @@ -59,7 +59,7 @@ void memcached_init(struct memcached_server *ptr, char *server_ip, int server_po int set_socket_options(struct memcached_server *ptr){ - int error, flag=1, flags, rval; + int error, flag=1, flags; struct timeval waittime; struct linger linger; @@ -128,8 +128,7 @@ int set_socket_options(struct memcached_server *ptr){ if((flags & O_NONBLOCK) == 0){ - rval = fcntl(ptr->fd, F_SETFL, flags | O_NONBLOCK); - if(rval == -1) return MEMCACHED_FAILURE; + if(fcntl(ptr->fd, F_SETFL, flags | O_NONBLOCK) == -1) return MEMCACHED_FAILURE; } return MEMCACHED_SUCCESS; @@ -223,7 +222,7 @@ int memcached_add(struct memcached_server *ptr, char *cmd, char *key, char *valu if(memcached_connect(ptr) != MEMCACHED_SUCCESS) return MEMCACHED_FAILURE; // cmd could be either 'add' or 'set' - snprintf(ptr->buf, MAXBUFSIZE-1, "%s %s %d %ld %d \r\n", cmd, key, flags, expiry, valuelen); + snprintf(ptr->buf, MAXBUFSIZE-1, "%s %s %u %lu %u \r\n", cmd, key, flags, expiry, valuelen); len = strlen(ptr->buf); strncat(ptr->buf, value, MAXBUFSIZE-strlen(ptr->buf)-1); @@ -263,52 +262,6 @@ int memcached_increment(struct memcached_server *ptr, char *key, unsigned long l } -char *memcached_get(struct memcached_server *ptr, char *key, unsigned int *len, unsigned int *flags){ - char *p; - - if(memcached_connect(ptr) != MEMCACHED_SUCCESS) return NULL; - - snprintf(ptr->buf, MAXBUFSIZE, "get %s \r\n", key); - send(ptr->fd, ptr->buf, strlen(ptr->buf), 0); - - ptr->last_read_bytes = __recvtimeout(ptr->fd, ptr->buf, MAXBUFSIZE, ptr->rcv_timeout); - - if(ptr->last_read_bytes <= 0){ - memcached_shutdown(ptr); - return NULL; - } - - - if(ptr->last_read_bytes < 10) return NULL; - - if(strncmp("VALUE ", ptr->buf, 6)) return NULL; - - p = strchr(ptr->buf, '\r'); - if(!p) return NULL; - *p = '\0'; - ptr->result = p + 2; - - p = strrchr(ptr->buf + 6, ' '); - if(!p) return NULL; - *len = atoi(p+1); - *p = '\0'; - - - p = strrchr(ptr->buf + 6, ' '); - if(!p) return NULL; - *flags = atoi(p+1); - *p = '\0'; - - - p = strchr(ptr->result, '\r'); - if(!p) return NULL; - - *p = '\0'; - - return ptr->result; -} - - int memcached_mget(struct memcached_server *ptr, char *key){ if(memcached_connect(ptr) != MEMCACHED_SUCCESS) return MEMCACHED_FAILURE; diff --git a/src/message.c b/src/message.c index 6279af31..7700fcdb 100644 --- a/src/message.c +++ b/src/message.c @@ -136,15 +136,6 @@ int store_recipients(struct session_data *sdata, char *to, uint64 id, struct con } -void remove_recipients(struct session_data *sdata, uint64 id){ - char s[SMALLBUFSIZE]; - - snprintf(s, sizeof(s)-1, "DELETE FROM " SQL_RECIPIENT_TABLE " WHERE id=%llu", id); - - p_query(sdata, s); -} - - int store_folder_id(struct session_data *sdata, struct data *data, uint64 id, struct config *cfg){ int rc=ERR; struct sql sql; diff --git a/src/misc.c b/src/misc.c index 82703acb..d723f9ec 100644 --- a/src/misc.c +++ b/src/misc.c @@ -88,44 +88,6 @@ long tvdiff(struct timeval a, struct timeval b){ } -/* - * count a character in buffer - */ - -int countCharacterInBuffer(char *p, char c){ - int i=0; - - for(; *p; p++){ - if(*p == c) - i++; - } - - return i; -} - - -void replaceCharacterInBuffer(char *p, char from, char to){ - size_t i; - int k=0; - - for(i=0; i 0){ - p[k] = to; - k++; - } - } - else { - p[k] = p[i]; - k++; - } - - } - - p[k] = '\0'; -} - - /* * split a string by a character as delimiter */ @@ -181,10 +143,8 @@ char *split_str(char *row, char *what, char *s, int size){ r += strlen(what); } - if(s != NULL){ - strncpy(s, row, len); - s[len] = '\0'; - } + strncpy(s, row, len); + s[len] = '\0'; return r; } @@ -215,8 +175,7 @@ int trimBuffer(char *s){ int extract_verp_address(char *email){ - char *p, *p1, *p2; - char puf[SMALLBUFSIZE]; + char *p1; // a VERP address is like archive+user=domain.com@myarchive.local @@ -226,13 +185,14 @@ int extract_verp_address(char *email){ p1 = strchr(email, '+'); if(p1){ - p2 = strchr(p1, '@'); + char *p2 = strchr(p1, '@'); if(p2 && p2 > p1 + 2){ if(strchr(p1+1, '=')){ + char puf[SMALLBUFSIZE]; memset(puf, 0, sizeof(puf)); memcpy(&puf[0], p1+1, p2-p1-1); - p = strchr(puf, '='); + char *p = strchr(puf, '='); if(p) *p = '@'; strcpy(email, puf); } @@ -349,10 +309,10 @@ int get_random_bytes(unsigned char *buf, int len, unsigned char server_id){ int readFromEntropyPool(int fd, void *_s, ssize_t n){ char *s = _s; - ssize_t res, pos = 0; + ssize_t pos = 0; while(n > pos){ - res = read(fd, s + pos, n - pos); + ssize_t res = read(fd, s + pos, n - pos); switch(res){ case -1: continue; case 0: return res; @@ -605,12 +565,6 @@ void strtolower(char *s){ } -void *get_in_addr(struct sockaddr *sa){ - if(sa->sa_family == AF_INET) return &(((struct sockaddr_in*)sa)->sin_addr); - return &(((struct sockaddr_in6*)sa)->sin6_addr); -} - - int make_socket_non_blocking(int fd){ int flags, s; diff --git a/src/misc.h b/src/misc.h index 7cd650c9..ed13c206 100644 --- a/src/misc.h +++ b/src/misc.h @@ -19,8 +19,6 @@ int get_build(); void get_extractor_list(); void __fatal(char *s); long tvdiff(struct timeval a, struct timeval b); -int countCharacterInBuffer(char *p, char c); -void replaceCharacterInBuffer(char *p, char from, char to); char *split(char *str, int ch, char *buf, int buflen, int *result); char *split_str(char *row, char *what, char *s, int size); int trimBuffer(char *s); @@ -42,7 +40,6 @@ void init_session_data(struct session_data *sdata, struct config *cfg); int read_from_stdin(struct session_data *sdata); void strtolower(char *s); -void *get_in_addr(struct sockaddr *sa); int make_socket_non_blocking(int fd); int create_and_bind(char *listen_addr, int listen_port); diff --git a/src/mydomains.c b/src/mydomains.c index a25bd25d..47f57fc2 100644 --- a/src/mydomains.c +++ b/src/mydomains.c @@ -11,7 +11,6 @@ void load_mydomains(struct session_data *sdata, struct data *data, struct config *cfg){ - int rc; char s[SMALLBUFSIZE]; struct sql sql; @@ -32,9 +31,7 @@ void load_mydomains(struct session_data *sdata, struct data *data, struct config p_store_results(&sql); while(p_fetch_results(&sql) == OK){ - rc = addnode(data->mydomains, s); - - if(rc == 0) syslog(LOG_PRIORITY, "failed to append mydomain: '%s'", s); + if(addnode(data->mydomains, s) == 0) syslog(LOG_PRIORITY, "failed to append mydomain: '%s'", s); else if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "added mydomain: '%s'", s); memset(s, 0, sizeof(s)); diff --git a/src/parser.c b/src/parser.c index 9882aad1..08fb682a 100644 --- a/src/parser.c +++ b/src/parser.c @@ -73,9 +73,7 @@ struct parser_state parse_message(struct session_data *sdata, int take_into_piec void post_parse(struct session_data *sdata, struct parser_state *state, struct config *cfg){ - int i, rec=0; - unsigned int len; - char *p; + int i; clearhash(state->boundaries); clearhash(state->rcpt); @@ -105,12 +103,12 @@ void post_parse(struct session_data *sdata, struct parser_state *state, struct c if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: attachment list: i:%d, name=*%s*, type: *%s*, size: %d, int.name: %s, digest: %s", sdata->ttmpfile, i, state->attachments[i].filename, state->attachments[i].type, state->attachments[i].size, state->attachments[i].internalname, state->attachments[i].digest); - p = determine_attachment_type(state->attachments[i].filename, state->attachments[i].type); - len = strlen(p); + char *p = determine_attachment_type(state->attachments[i].filename, state->attachments[i].type); + unsigned int len = strlen(p); if(strlen(sdata->attachments) < SMALLBUFSIZE-len-1 && !strstr(sdata->attachments, p)) memcpy(&(sdata->attachments[strlen(sdata->attachments)]), p, len); if(state->attachments[i].dumped == 1){ - rec = 0; + int rec = 0; if(cfg->extract_attachments == 1 && state->bodylen < BIGBUFSIZE-1024) extract_attachment_content(sdata, state, state->attachments[i].aname, get_attachment_extractor_by_filename(state->attachments[i].filename), &rec, cfg); unlink(state->attachments[i].aname); @@ -153,15 +151,13 @@ void storno_attachment(struct parser_state *state){ void flush_attachment_buffer(struct parser_state *state, char *abuffer, unsigned int abuffersize){ - int n64; - unsigned char b64buffer[MAXBUFSIZE]; - if(write(state->fd, abuffer, state->abufpos) == -1) syslog(LOG_PRIORITY, "ERROR: write(), %s, %d, %s", __func__, __LINE__, __FILE__); if(state->b64fd != -1){ abuffer[state->abufpos] = '\0'; if(state->base64 == 1){ - n64 = base64_decode_attachment_buffer(abuffer, &b64buffer[0], sizeof(b64buffer)); + unsigned char b64buffer[MAXBUFSIZE]; + int n64 = base64_decode_attachment_buffer(abuffer, &b64buffer[0], sizeof(b64buffer)); if(write(state->b64fd, b64buffer, n64) == -1) syslog(LOG_PRIORITY, "ERROR: write(), %s, %d, %s", __func__, __LINE__, __FILE__); } else if(write(state->b64fd, abuffer, state->abufpos) == -1){ @@ -175,9 +171,8 @@ void flush_attachment_buffer(struct parser_state *state, char *abuffer, unsigned int parse_line(char *buf, struct parser_state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, unsigned int writebuffersize, char *abuffer, unsigned int abuffersize, struct data *data, struct config *cfg){ - char *p, puf[SMALLBUFSIZE]; - char tmpbuf[MAXBUFSIZE]; - int writelen, boundary_line=0, result; + char *p; + int boundary_line=0; unsigned int len; if(cfg->debug == 1) printf("line: %s", buf); @@ -284,8 +279,9 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata syslog(LOG_PRIORITY, "%s: error opening %s", sdata->ttmpfile, state->attachments[state->n_attachments].internalname); } else { + char puf[SMALLBUFSIZE]; snprintf(puf, sizeof(puf)-1, "ATTACHMENT_POINTER_%s.a%d_XXX_PILER", sdata->ttmpfile, state->n_attachments); - writelen = strlen(puf); + int writelen = strlen(puf); if(writelen + state->writebufpos > writebuffersize-1){ if(write(state->mfd, writebuffer, state->writebufpos) == -1) syslog(LOG_PRIORITY, "ERROR: write(), %s, %d, %s", __func__, __LINE__, __FILE__); state->writebufpos = 0; @@ -637,7 +633,8 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata /* encode the body if it's not utf-8 encoded */ if(state->message_state == MSG_BODY && state->utf8 != 1){ - result = utf8_encode(buf, strlen(buf), &tmpbuf[0], sizeof(tmpbuf), state->charset); + char tmpbuf[MAXBUFSIZE]; + int result = utf8_encode(buf, strlen(buf), &tmpbuf[0], sizeof(tmpbuf), state->charset); if(result == OK) snprintf(buf, MAXBUFSIZE-1, "%s", tmpbuf); } diff --git a/src/parser_utils.c b/src/parser_utils.c index e88d19fb..7481f2db 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -114,7 +114,7 @@ long get_local_timezone_offset(){ time_t parse_date_header(char *datestr){ - int n=0, len; + int n=0; long offset=0; time_t ts=0; char *p, *q, *r, *tz, s[SMALLBUFSIZE], tzh[4], tzm[3]; @@ -150,7 +150,7 @@ time_t parse_date_header(char *datestr){ do { p = split_str(p, " ", s, sizeof(s)-1); - len = strlen(s); + int len = strlen(s); if(len > 0){ n++; @@ -264,7 +264,7 @@ time_t parse_date_header(char *datestr){ int extract_boundary(char *p, struct parser_state *state){ - char *q, *q2; + char *q; p += strlen("boundary"); @@ -291,7 +291,7 @@ int extract_boundary(char *p, struct parser_state *state){ break; } - q2 = strchr(p, ';'); + char *q2 = strchr(p, ';'); if(q2) *q2 = '\0'; q = strrchr(p, '"'); @@ -315,14 +315,13 @@ int extract_boundary(char *p, struct parser_state *state){ void fixupEncodedHeaderLine(char *buf, int buflen){ - char *p, *q, *r, *s, *e, *end; + char *q, *r, *s, *e, *end; /* * I thought SMALLBUFSIZE would be enough for v, encoding and tmpbuf(2*), * but then I saw a 6-7000 byte long subject line, so I've switched to MAXBUFSIZE */ char v[MAXBUFSIZE], u[MAXBUFSIZE], puf[MAXBUFSIZE], encoding[MAXBUFSIZE], tmpbuf[2*MAXBUFSIZE]; int need_encoding, ret, prev_encoded=0, n_tokens=0; - int b64=0, qp=0; if(buflen < 5) return; @@ -333,7 +332,7 @@ void fixupEncodedHeaderLine(char *buf, int buflen){ do { q = split_str(q, " ", v, sizeof(v)-1); - p = v; + char *p = v; do { memset(u, 0, sizeof(u)); @@ -349,7 +348,7 @@ void fixupEncodedHeaderLine(char *buf, int buflen){ * Happy New Year! =?utf-8?q?=F0=9F=8E=86?= */ - b64 = qp = 0; + int b64=0, qp=0; memset(encoding, 0, sizeof(encoding)); r = strstr(p, "=?"); @@ -446,9 +445,9 @@ void fixupEncodedHeaderLine(char *buf, int buflen){ void fixupSoftBreakInQuotedPritableLine(char *buf, struct parser_state *state){ int i=0; - char *p, puf[MAXBUFSIZE]; if(strlen(state->qpbuf) > 0){ + char puf[MAXBUFSIZE]; memset(puf, 0, sizeof(puf)); snprintf(puf, sizeof(puf)-1, "%s%s", state->qpbuf, buf); snprintf(buf, MAXBUFSIZE-1, "%s", puf); @@ -461,7 +460,7 @@ void fixupSoftBreakInQuotedPritableLine(char *buf, struct parser_state *state){ } if(i == 1){ - p = strrchr(buf, ' '); + char *p = strrchr(buf, ' '); if(p){ memset(state->qpbuf, 0, MAX_TOKEN_LEN); if(strlen(p) < MAX_TOKEN_LEN-1){ @@ -475,9 +474,8 @@ void fixupSoftBreakInQuotedPritableLine(char *buf, struct parser_state *state){ void fixupBase64EncodedLine(char *buf, struct parser_state *state){ - char *p, puf[MAXBUFSIZE]; - if(strlen(state->miscbuf) > 0){ + char puf[MAXBUFSIZE]; memset(puf, 0, sizeof(puf)); strncpy(puf, state->miscbuf, sizeof(puf)-strlen(puf)-1); strncat(puf, buf, sizeof(puf)-strlen(puf)-1); @@ -489,7 +487,7 @@ void fixupBase64EncodedLine(char *buf, struct parser_state *state){ } if(buf[strlen(buf)-1] != '\n'){ - p = strrchr(buf, ' '); + char *p = strrchr(buf, ' '); if(p){ memcpy(&(state->miscbuf[0]), p+1, MAX_TOKEN_LEN-1); *p = '\0'; @@ -576,7 +574,7 @@ void markHTML(char *buf, struct parser_state *state){ int appendHTMLTag(char *buf, char *htmlbuf, int pos, struct parser_state *state){ - char *p, html[SMALLBUFSIZE]; + char html[SMALLBUFSIZE]; int len; if(pos == 0 && strncmp(htmlbuf, "style ", 6) == 0) state->style = 1; @@ -594,7 +592,7 @@ int appendHTMLTag(char *buf, char *htmlbuf, int pos, struct parser_state *state) len = strlen(html); if(len > 8 && strchr(html, '=')){ - p = strstr(html, "cid:"); + char *p = strstr(html, "cid:"); if(p){ *(p+3) = '\0'; strncat(html, " ", SMALLBUFSIZE-1); @@ -697,11 +695,9 @@ int does_it_seem_like_an_email_address(char *email){ void add_recipient(char *email, unsigned int len, struct session_data *sdata, struct parser_state *state, struct data *data, struct config *cfg){ - char *q; - if(findnode(state->rcpt, email) == NULL){ - q = strchr(email, '@'); + char *q = strchr(email, '@'); /* skip any address matching ...@cfg->hostid, 2013.10.29, SJ */ if(q && strncmp(q+1, cfg->hostid, cfg->hostid_len) == 0){ @@ -769,7 +765,7 @@ void degenerateToken(unsigned char *p){ int i=1, d=0, dp=0; unsigned char *s; - /* quit if this the string does not end with a punctuation character */ + /* quit if the string does not end with a punctuation character */ if(!ispunct(*(p+strlen((char *)p)-1))) return; @@ -825,8 +821,7 @@ void fixURL(char *buf, int buflen){ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultbuflen){ - int extended=0; - char buf[SMALLBUFSIZE], puf[SMALLBUFSIZE], *p, *q, *encoding; + char buf[SMALLBUFSIZE], *p, *q; snprintf(buf, sizeof(buf)-1, "%s", s); @@ -862,6 +857,8 @@ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultb * */ + int extended=0; + p += strlen(name); if(*p == '*'){ extended = 1; @@ -889,7 +886,7 @@ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultb if(extended == 1){ - encoding = p; + char *encoding = p; q = strchr(p, '\''); if(q){ *q = '\0'; @@ -906,6 +903,7 @@ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultb snprintf(resultbuf, resultbuflen-2, "%s", p); } else { + char puf[SMALLBUFSIZE]; snprintf(puf, sizeof(puf)-1, "%s", p); fixupEncodedHeaderLine(puf, sizeof(puf)); @@ -919,8 +917,6 @@ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultb char *determine_attachment_type(char *filename, char *type){ - char *p; - if(strncasecmp(type, "text/", strlen("text/")) == 0) return "text,"; if(strncasecmp(type, "image/", strlen("image/")) == 0) return "image,"; if(strncasecmp(type, "audio/", strlen("audio/")) == 0) return "audio,"; @@ -951,7 +947,7 @@ char *determine_attachment_type(char *filename, char *type){ if(strncasecmp(type, "application/", 12) == 0){ - p = strrchr(filename, '.'); + char *p = strrchr(filename, '.'); if(p){ p++; @@ -1013,14 +1009,13 @@ char *get_attachment_extractor_by_filename(char *filename){ void parse_reference(struct parser_state *state, char *s){ - int len; char puf[SMALLBUFSIZE]; if(strlen(state->reference) > 10) return; do { s = split_str(s, " ", puf, sizeof(puf)-1); - len = strlen(puf); + int len = strlen(puf); if(len > 10 && len < SMALLBUFSIZE-1){ memcpy(&(state->reference[strlen(state->reference)]), puf, len); @@ -1046,12 +1041,11 @@ int base64_decode_attachment_buffer(char *p, unsigned char *b, int blen){ void fix_plus_sign_in_email_address(char *puf, char **at_sign, unsigned int *len){ - int n; char *r; r = strchr(puf, '+'); if(r){ - n = strlen(*at_sign); + int n = strlen(*at_sign); memmove(r, *at_sign, n); *(r+n) = '\0'; *len = strlen(puf); diff --git a/src/pop3.c b/src/pop3.c index ec3a5e2c..c8ab4194 100644 --- a/src/pop3.c +++ b/src/pop3.c @@ -63,7 +63,7 @@ int connect_to_pop3_server(struct data *data){ void get_number_of_total_messages(struct data *data){ - char *p, buf[MAXBUFSIZE]; + char buf[MAXBUFSIZE]; data->import->total_messages = 0; @@ -73,7 +73,7 @@ void get_number_of_total_messages(struct data *data){ recvtimeoutssl(data->net, buf, sizeof(buf)); if(strncmp(buf, "+OK ", 4) == 0){ - p = strchr(&buf[4], ' '); + char *p = strchr(&buf[4], ' '); if(p){ *p = '\0'; data->import->total_messages = atoi(&buf[4]); @@ -86,7 +86,7 @@ void get_number_of_total_messages(struct data *data){ int pop3_download_email(struct data *data, int i){ - int n, fd, pos=0, readlen=0, lastpos=0, nreads=0; + int n, fd, pos=0, lastpos=0, nreads=0; char *p, buf[MAXBUFSIZE]; char aggrbuf[3*MAXBUFSIZE]; @@ -108,7 +108,6 @@ int pop3_download_email(struct data *data, int i){ while((n = recvtimeoutssl(data->net, buf, sizeof(buf))) > 0){ nreads++; - readlen += n; if(nreads == 1){ @@ -167,7 +166,6 @@ void pop3_delete_message(struct data *data, int i){ void process_pop3_emails(struct session_data *sdata, struct data *data, struct config *cfg){ - int i=0, rc=ERR; char buf[MAXBUFSIZE]; data->import->processed_messages = 0; @@ -178,12 +176,12 @@ void process_pop3_emails(struct session_data *sdata, struct data *data, struct c if(data->import->total_messages <= 0) return; - for(i=data->import->start_position; i<=data->import->total_messages; i++){ + for(int i=data->import->start_position; i<=data->import->total_messages; i++){ if(pop3_download_email(data, i) == OK){ if(data->quiet == 0){ printf("processed: %7d [%3d%%]\r", data->import->processed_messages, 100*i/data->import->total_messages); fflush(stdout); } if(data->import->dryrun == 0){ - rc = import_message(sdata, data, cfg); + int rc = import_message(sdata, data, cfg); if(data->import->remove_after_import == 1 && rc == OK){ pop3_delete_message(data, i); diff --git a/src/reindex.c b/src/reindex.c index b84a9891..2382d9f5 100644 --- a/src/reindex.c +++ b/src/reindex.c @@ -74,10 +74,7 @@ uint64 get_max_meta_id(struct session_data *sdata){ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct data *data, uint64 from_id, uint64 to_id, struct config *cfg){ - FILE *f; - char filename[SMALLBUFSIZE]; char s[SMALLBUFSIZE]; - int rc=0; uint64 stored_id=0, reindexed=0, delta; struct parser_state state; struct sql sql; @@ -111,12 +108,12 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct data *da while(p_fetch_results(&sql) == OK){ if(stored_id > 0){ - + char filename[SMALLBUFSIZE]; snprintf(filename, sizeof(filename)-1, "%llu.eml", stored_id); - f = fopen(filename, "w"); + FILE *f = fopen(filename, "w"); if(f){ - rc = retrieve_email_from_archive(sdata, f, cfg); + int rc = retrieve_email_from_archive(sdata, f, cfg); fclose(f); if(rc){ @@ -162,7 +159,7 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct data *da int main(int argc, char **argv){ - int c, all=0; + int all=0; uint64 from_id=0, to_id=0, n=0; char *configfile=CONFIG_FILE, *folder=NULL; struct session_data sdata; @@ -171,7 +168,7 @@ int main(int argc, char **argv){ while(1){ - c = getopt(argc, argv, "c:f:t:F:pahv?"); + int c = getopt(argc, argv, "c:f:t:F:pahv?"); if(c == -1) break; @@ -211,7 +208,7 @@ int main(int argc, char **argv){ } - if(all == 0 && (from_id <= 0 || to_id <= 0) ) usage(); + if(all == 0 && (from_id == 0 || to_id == 0) ) usage(); if(!can_i_write_directory(NULL)) __fatal("cannot write current directory!"); diff --git a/src/rules.c b/src/rules.c index d78472e2..ec667420 100644 --- a/src/rules.c +++ b/src/rules.c @@ -196,13 +196,14 @@ struct rule *create_rule_item(struct rule_cond *rule_cond){ int count_match(struct rule *p, struct parser_state *state, int size, int spam){ int ismatch=0; - size_t nmatch=0; ismatch += check_spam_rule(spam, p->spam); ismatch += check_size_rule(size, p->size, p->_size); ismatch += check_attachment_rule(state, p); if(p->compiled == 1){ + size_t nmatch=0; + if(p->emptyfrom == 1){ ismatch += RULE_UNDEF; } @@ -338,7 +339,6 @@ int check_spam_rule(int is_spam, int spam){ int check_attachment_rule(struct parser_state *state, struct rule *rule){ int i; size_t nmatch=0; - int ismatch = 0; // If no attachment rule, then return RULE_UNDEF if(rule->emptyaname == 1 && rule->emptyatype == 1 && rule->attachment_size == 0) return RULE_UNDEF; @@ -348,7 +348,7 @@ int check_attachment_rule(struct parser_state *state, struct rule *rule){ for(i=1; i<=state->n_attachments; i++){ - ismatch = 0; + int ismatch = 0; if(rule->emptyaname == 0){ if(regexec(&(rule->attachment_name), state->attachments[i].filename, nmatch, NULL, 0) == 0) @@ -379,34 +379,32 @@ void initrules(struct node *xhash[]){ void clearrules(struct node *xhash[]){ - struct node *p, *q; + struct node *q; struct rule *rule; q = xhash[0]; while(q != NULL){ - p = q; + struct node *p = q; q = q->r; - if(p){ - if(p->str){ - rule = (struct rule*)p->str; + if(p->str){ + rule = (struct rule*)p->str; - regfree(&(rule->from)); - regfree(&(rule->to)); - regfree(&(rule->subject)); - regfree(&(rule->body)); - regfree(&(rule->attachment_name)); - regfree(&(rule->attachment_type)); + regfree(&(rule->from)); + regfree(&(rule->to)); + regfree(&(rule->subject)); + regfree(&(rule->body)); + regfree(&(rule->attachment_name)); + regfree(&(rule->attachment_type)); - free(rule->rulestr); + free(rule->rulestr); - if(rule->domain) free(rule->domain); + if(rule->domain) free(rule->domain); - free(rule); - } - free(p); + free(rule); } + free(p); } xhash[0] = NULL; diff --git a/src/session.c b/src/session.c index 8d1c7a79..b1cacb7e 100644 --- a/src/session.c +++ b/src/session.c @@ -30,7 +30,6 @@ int is_blocked_by_tcp_wrappers(int sd){ int start_new_session(struct smtp_session **sessions, int socket, int *num_connections, struct config *cfg){ - char smtp_banner[SMALLBUFSIZE]; int slot; /* @@ -57,6 +56,8 @@ int start_new_session(struct smtp_session **sessions, int socket, int *num_conne sessions[slot] = malloc(sizeof(struct smtp_session)); if(sessions[slot]){ init_smtp_session(sessions[slot], slot, socket, cfg); + + char smtp_banner[SMALLBUFSIZE]; snprintf(smtp_banner, sizeof(smtp_banner)-1, SMTP_RESP_220_BANNER, cfg->hostid); send(socket, smtp_banner, strlen(smtp_banner), 0); @@ -233,14 +234,12 @@ void handle_data(struct smtp_session *session, char *readbuf, int readlen, struc void write_envelope_addresses(struct smtp_session *session, struct config *cfg){ - int i; - char *p, s[SMALLBUFSIZE]; - if(session->fd == -1) return; - for(i=0; inum_of_rcpt_to; i++){ - p = strchr(session->rcptto[i], '@'); + for(int i=0; inum_of_rcpt_to; i++){ + char *p = strchr(session->rcptto[i], '@'); if(p && strncmp(p+1, cfg->hostid, cfg->hostid_len)){ + char s[SMALLBUFSIZE]; snprintf(s, sizeof(s)-1, "X-Piler-Envelope-To: %s\n", session->rcptto[i]); if(write(session->fd, s, strlen(s)) == -1) syslog(LOG_PRIORITY, "ERROR: %s: cannot write envelope to address", session->ttmpfile); } diff --git a/src/smtp.c b/src/smtp.c index 4ce18239..bd40af02 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -72,15 +72,15 @@ void process_smtp_command(struct smtp_session *session, char *buf, struct config void process_data(struct smtp_session *session, char *buf, int buflen){ - int len=0, written=0, n_writes=0; - if(session->last_data_char == '\n' && strcmp(buf, ".\r\n") == 0){ process_command_period(session); } else { // write line to file + int written=0, n_writes=0; + while(written < buflen) { - len = write(session->fd, buf+written, buflen-written); + int len = write(session->fd, buf+written, buflen-written); n_writes++; if(len > 0){ @@ -98,7 +98,6 @@ void process_data(struct smtp_session *session, char *buf, int buflen){ void wait_for_ssl_accept(struct smtp_session *session){ int rc; - char ssl_error[SMALLBUFSIZE]; if(session->cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "waiting for ssl handshake"); @@ -115,6 +114,8 @@ void wait_for_ssl_accept(struct smtp_session *session){ } if(session->cfg->verbosity >= _LOG_DEBUG || session->net.use_ssl == 0){ + char ssl_error[SMALLBUFSIZE]; + ERR_error_string_n(ERR_get_error(), ssl_error, SMALLBUFSIZE); syslog(LOG_PRIORITY, "SSL_accept() result, rc=%d, errorcode: %d, error text: %s", rc, SSL_get_error(session->net.ssl, rc), ssl_error); diff --git a/src/stats.c b/src/stats.c index 68454a84..4b75db71 100644 --- a/src/stats.c +++ b/src/stats.c @@ -134,15 +134,15 @@ void sphinx_queries(struct session_data *sdata, struct stats *stats){ void count_error_emails(struct stats *stats){ DIR *dir; - struct dirent *de; struct stat st; - char buf[SMALLBUFSIZE]; dir = opendir(ERROR_DIR); if(dir){ + struct dirent *de; while((de = readdir(dir))){ if(strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; + char buf[SMALLBUFSIZE]; snprintf(buf, sizeof(buf)-1, "%s/%s", ERROR_DIR, de->d_name); if(stat(buf, &st) == 0 && S_ISREG(st.st_mode)){ diff --git a/src/store.c b/src/store.c index dc3839a1..d903282d 100644 --- a/src/store.c +++ b/src/store.c @@ -213,12 +213,11 @@ ENDE: int remove_stored_message_files(struct session_data *sdata, struct parser_state *state, struct config *cfg){ - int i; char s[SMALLBUFSIZE]; if(state->n_attachments > 0){ - for(i=1; i<=state->n_attachments; i++){ + for(int i=1; i<=state->n_attachments; i++){ snprintf(s, sizeof(s)-1, "%s/%02x/%c%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, cfg->server_id, sdata->ttmpfile[8], sdata->ttmpfile[9], sdata->ttmpfile[10], sdata->ttmpfile[RND_STR_LEN-4], sdata->ttmpfile[RND_STR_LEN-3], sdata->ttmpfile[RND_STR_LEN-2], sdata->ttmpfile[RND_STR_LEN-1], sdata->ttmpfile, i); if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: unlinking %s", sdata->ttmpfile, s); diff --git a/src/tai.c b/src/tai.c index 344ee094..00f95465 100644 --- a/src/tai.c +++ b/src/tai.c @@ -4,7 +4,6 @@ #include #include "tai.h" -static char hex[16] = "0123456789abcdef"; void tai_pack(char *s, struct tai *t){ @@ -50,21 +49,3 @@ void taia_now(struct taia *t){ t->nano = 1000 * now.tv_usec + 500; t->atto = 0; } - - -void tai_timestamp(char *s){ - struct tai now; - char nowpack[TAI_PACK]; - int i; - - now.x = 4611686018427387914ULL + (uint64)time((long *) 0); - - tai_pack(nowpack, &now); - - for (i = 0;i < 8;++i) { - *(s+i*2) = hex[(nowpack[i] >> 4) & 15]; - *(s+i*2+1) = hex[nowpack[i] & 15]; - } - - *(s+2*TAI_PACK) = '\0'; -} diff --git a/src/test.c b/src/test.c index 497c77fb..91e2bcfc 100644 --- a/src/test.c +++ b/src/test.c @@ -28,7 +28,7 @@ void usage(){ int main(int argc, char **argv){ - int i, c; + int i; time_t retention_seconds=0; struct stat st; struct session_data sdata; @@ -57,9 +57,9 @@ int main(int argc, char **argv){ int option_index = 0; - c = getopt_long(argc, argv, "c:m:a:hv?", long_options, &option_index); + int c = getopt_long(argc, argv, "c:m:a:hv?", long_options, &option_index); #else - c = getopt(argc, argv, "c:m:a:hv?"); + int c = getopt(argc, argv, "c:m:a:hv?"); #endif if(c == -1) break; diff --git a/suppressions.txt b/suppressions.txt new file mode 100644 index 00000000..a50ff542 --- /dev/null +++ b/suppressions.txt @@ -0,0 +1,13 @@ +identicalConditionAfterEarlyExit:src/tokenizer.c:40 +invalidPrintfArgType_s:src/extract.c:175 +invalidPrintfArgType_s:src/misc.c:39 +invalidPrintfArgType_s:src/misc.c:43 +invalidPrintfArgType_s:src/misc.c:47 +invalidPrintfArgType_s:src/misc.c:51 +invalidPrintfArgType_s:src/misc.c:55 +invalidPrintfArgType_s:src/misc.c:59 +invalidPrintfArgType_s:src/misc.c:63 +redundantAssignment:src/imap.c:47 +unusedFunction:src/sig.c:33 +unusedFunction:src/sig.c:38 +unusedFunction:src/sig.c:44 diff --git a/unit_tests/check_digest.c b/unit_tests/check_digest.c index 23f490a9..9d5bf37d 100644 --- a/unit_tests/check_digest.c +++ b/unit_tests/check_digest.c @@ -5,7 +5,7 @@ #include "test.h" -struct digest_test tests[] = { +struct digest_test emls[] = { {"1.eml", "7fa4f06f7085986007454b374f6685e4cf838d9e9f8878f3cba89cfe98e29f56", "bbbafb22e2d4c035584a5024e9d4feaf32172559b4d7cacc8b7af4bd548da53e"}, {"2.eml", "668cb3b91b944af786667323442576b9813d65f3cd3bc33e9d5da303c79de038", "de90475409dd6ab24e80c1b7a987715c40fe8d28d91337b7f063b477159c7b3c"}, {"3.eml", "0d546d4cb4a8ce74ea5fd4cc51dbb4ebeaa7542f1c691817579da7eeab8d4771", "f585d011340d292ee52ddedb07cda662a8f1e46329d14a2ce92dca0604387bab"}, @@ -41,9 +41,9 @@ static void test_digest_file(){ unsigned int i; char digest[2*DIGEST_LENGTH+1]; - for(i=0; i= -3600, date_test[i].date_str); } diff --git a/unit_tests/smtp.c b/unit_tests/smtp.c index acb6337d..31914c74 100644 --- a/unit_tests/smtp.c +++ b/unit_tests/smtp.c @@ -27,10 +27,10 @@ void connect_to_smtp_server(char *server, int port, struct data *data){ char port_string[8], buf[MAXBUFSIZE]; struct addrinfo hints, *res; - data->net->socket = -1; - if(data == NULL) return; + data->net->socket = -1; + snprintf(port_string, sizeof(port_string)-1, "%d", port); memset(&hints, 0, sizeof(hints)); @@ -301,7 +301,7 @@ static void test_smtp_commands_period_command_in_its_own_packet(char *server, in int main(int argc, char **argv){ - int c, port=25; + int port=25; char *server=NULL; struct data data; struct net net; @@ -325,9 +325,9 @@ int main(int argc, char **argv){ int option_index = 0; - c = getopt_long(argc, argv, "c:s:p:t:lh?", long_options, &option_index); + int c = getopt_long(argc, argv, "c:s:p:t:lh?", long_options, &option_index); #else - c = getopt(argc, argv, "c:s:p:t:lh?"); + int c = getopt(argc, argv, "c:s:p:t:lh?"); #endif