aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-05-31 17:17:13 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-05-31 17:17:13 +0400
commit0612e84b3cec508c3d62d38c4e2682c85cc808bb (patch)
treedb777e38f9c528127e195ad01da6a3088dc6da4a
parentae3eb4dfd787052bebc732c3e37b56f0800e1aa2 (diff)
downloadrspamd-0612e84b3cec508c3d62d38c4e2682c85cc808bb.tar.gz
rspamd-0612e84b3cec508c3d62d38c4e2682c85cc808bb.zip
* Fix strict aliasing while compiling with optimization
* Fix tanhl detection for platforms that have not implementation of it * Remove several compile warnings
-rw-r--r--CMakeLists.txt1
-rw-r--r--config.h.in2
-rw-r--r--src/cfg_utils.c8
-rw-r--r--src/cfg_xml.c17
-rw-r--r--src/classifiers/winnow.c2
-rw-r--r--src/evdns/CMakeLists.txt2
-rw-r--r--src/expressions.c3
-rw-r--r--src/lmtp.c16
-rw-r--r--src/logger.c5
-rw-r--r--src/main.h8
-rw-r--r--src/memcached.c4
-rw-r--r--src/plugins/custom/ipmark/ipmark.c6
-rw-r--r--src/settings.c6
-rw-r--r--src/smtp.c18
-rw-r--r--src/statfile.c2
-rw-r--r--src/symbols_cache.c2
-rw-r--r--src/worker.c16
17 files changed, 72 insertions, 46 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 615cbb52f..233741405 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -280,6 +280,7 @@ CHECK_FUNCTION_EXISTS(vfork HAVE_VFORK)
CHECK_FUNCTION_EXISTS(wait4 HAVE_WAIT4)
CHECK_FUNCTION_EXISTS(waitpid HAVE_WAITPID)
CHECK_FUNCTION_EXISTS(flock HAVE_FLOCK)
+CHECK_FUNCTION_EXISTS(tanhl HAVE_TANHL)
CHECK_SYMBOL_EXISTS(PATH_MAX limits.h HAVE_PATH_MAX)
CHECK_SYMBOL_EXISTS(MAXPATHLEN sys/param.h HAVE_MAXPATHLEN)
diff --git a/config.h.in b/config.h.in
index 99ea39c5b..ebb48f508 100644
--- a/config.h.in
+++ b/config.h.in
@@ -96,6 +96,8 @@
#cmakedefine HAVE_FLOCK 1
+#cmakedefine HAVE_TANHL 1
+
#cmakedefine HAVE_SA_SIGINFO 1
#cmakedefine DEBUG_MODE 1
diff --git a/src/cfg_utils.c b/src/cfg_utils.c
index d63e6bc93..21cf57481 100644
--- a/src/cfg_utils.c
+++ b/src/cfg_utils.c
@@ -727,7 +727,15 @@ internal_normalizer_func (struct config_file *cfg, long double score, void *data
return score;
}
else {
+#ifdef HAVE_TANHL
return max * tanhl (score / max);
+#else
+ /*
+ * As some implementations of libm does not support tanhl, try to use
+ * tanh
+ */
+ return max * tanh ((double) (score / max));
+#endif
}
return score;
diff --git a/src/cfg_xml.c b/src/cfg_xml.c
index 18314106b..f8b3f55ba 100644
--- a/src/cfg_xml.c
+++ b/src/cfg_xml.c
@@ -744,11 +744,12 @@ handle_lua (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GHashTable
lua_file = basename (tmp2);
if (lua_dir && lua_file) {
cur_dir = g_malloc (PATH_MAX);
- getcwd (cur_dir, PATH_MAX);
- if (chdir (lua_dir) != -1) {
+ if (getcwd (cur_dir, PATH_MAX) != NULL && chdir (lua_dir) != -1) {
if (luaL_dofile (L, lua_file) != 0) {
msg_err ("cannot load lua file %s: %s", val, lua_tostring (L, -1));
- chdir (cur_dir);
+ if (chdir (cur_dir) == -1) {
+ msg_err ("cannot chdir to %s: %s", cur_dir, strerror (errno));;
+ }
g_free (cur_dir);
g_free (tmp1);
g_free (tmp2);
@@ -757,14 +758,18 @@ handle_lua (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GHashTable
}
else {
msg_err ("cannot chdir to %s: %s", lua_dir, strerror (errno));;
- chdir (cur_dir);
+ if (chdir (cur_dir) == -1) {
+ msg_err ("cannot chdir to %s: %s", cur_dir, strerror (errno));;
+ }
g_free (cur_dir);
g_free (tmp1);
g_free (tmp2);
return FALSE;
}
- chdir (cur_dir);
+ if (chdir (cur_dir) == -1) {
+ msg_err ("cannot chdir to %s: %s", cur_dir, strerror (errno));;
+ }
g_free (cur_dir);
g_free (tmp1);
g_free (tmp2);
@@ -814,9 +819,11 @@ handle_module_path (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GH
cfg->script_modules = g_list_prepend (cfg->script_modules, cur);
}
globfree (&globbuf);
+ g_free (pattern);
}
else {
msg_err ("glob failed: %s", strerror (errno));
+ g_free (pattern);
return FALSE;
}
}
diff --git a/src/classifiers/winnow.c b/src/classifiers/winnow.c
index 6c64cdc4b..9f66c3cbd 100644
--- a/src/classifiers/winnow.c
+++ b/src/classifiers/winnow.c
@@ -335,7 +335,7 @@ winnow_learn (struct classifier_ctx *ctx, statfile_pool_t *pool, stat_file_t *fi
char *value;
int nodes, minnodes, iterations = 0;
struct statfile *st;
- stat_file_t *sel;
+ stat_file_t *sel = NULL;
long double res = 0., max = 0.;
GList *cur;
diff --git a/src/evdns/CMakeLists.txt b/src/evdns/CMakeLists.txt
index 338da91a9..aef7f95d2 100644
--- a/src/evdns/CMakeLists.txt
+++ b/src/evdns/CMakeLists.txt
@@ -2,4 +2,4 @@
SET(EVDNSSRC evdns.c)
ADD_LIBRARY(rspamd_evdns STATIC ${EVDNSSRC})
-SET_TARGET_PROPERTIES(rspamd_evdns PROPERTIES COMPILE_FLAGS "-DRSPAMD_LIB")
+SET_TARGET_PROPERTIES(rspamd_evdns PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing -DRSPAMD_LIB")
diff --git a/src/expressions.c b/src/expressions.c
index 25d950904..a8d639325 100644
--- a/src/expressions.c
+++ b/src/expressions.c
@@ -1306,9 +1306,10 @@ is_recipient_list_sorted (const InternetAddressList * ia)
return FALSE;
}
#ifdef GMIME24
+ num = internet_address_list_length ((InternetAddressList *)ia);
cur = ia;
for (i = 0; i < num; i ++) {
- addr = internet_address_list_get_address (cur, i);
+ addr = internet_address_list_get_address ((InternetAddressList *)cur, i);
current.addr = (char *)internet_address_get_name (addr);
if (previous.addr != NULL) {
if (g_ascii_strcasecmp (current.addr, previous.addr) < 0) {
diff --git a/src/lmtp.c b/src/lmtp.c
index 9f7a4805a..385debfbb 100644
--- a/src/lmtp.c
+++ b/src/lmtp.c
@@ -224,14 +224,13 @@ static void
accept_socket (int fd, short what, void *arg)
{
struct rspamd_worker *worker = (struct rspamd_worker *)arg;
- struct sockaddr_storage ss;
- struct sockaddr_in *sin;
+ union sa_union su;
struct worker_task *new_task;
struct rspamd_lmtp_proto *lmtp;
- socklen_t addrlen = sizeof (ss);
+ socklen_t addrlen = sizeof (su.ss);
int nfd;
- if ((nfd = accept_from_socket (fd, (struct sockaddr *)&ss, &addrlen)) == -1) {
+ if ((nfd = accept_from_socket (fd, (struct sockaddr *)&su.ss, &addrlen)) == -1) {
msg_warn ("accept failed: %s", strerror (errno));
return;
}
@@ -240,14 +239,13 @@ accept_socket (int fd, short what, void *arg)
new_task = construct_task (worker);
- if (ss.ss_family == AF_UNIX) {
+ if (su.ss.ss_family == AF_UNIX) {
msg_info ("accepted connection from unix socket");
new_task->client_addr.s_addr = INADDR_NONE;
}
- else if (ss.ss_family == AF_INET) {
- sin = (struct sockaddr_in *)&ss;
- msg_info ("accepted connection from %s port %d", inet_ntoa (sin->sin_addr), ntohs (sin->sin_port));
- memcpy (&new_task->client_addr, &sin->sin_addr, sizeof (struct in_addr));
+ else if (su.ss.ss_family == AF_INET) {
+ msg_info ("accepted connection from %s port %d", inet_ntoa (su.s4.sin_addr), ntohs (su.s4.sin_port));
+ memcpy (&new_task->client_addr, &su.s4.sin_addr, sizeof (struct in_addr));
}
new_task->sock = nfd;
diff --git a/src/logger.c b/src/logger.c
index a27cc27fc..282506df4 100644
--- a/src/logger.c
+++ b/src/logger.c
@@ -118,7 +118,10 @@ direct_write_log_line (void *data, int count, gboolean is_iov)
}
else if (errno == EFAULT || errno == EINVAL || errno == EFBIG || errno == ENOSPC) {
/* Rare case */
- (void)write (rspamd_log->fd, errmsg, r);
+ if (write (rspamd_log->fd, errmsg, r) == -1) {
+ /* Don't know what to do */
+ exit (EXIT_FAILURE);
+ }
}
else if (errno == EPIPE) {
/* We write to some pipe and it disappears, disable logging */
diff --git a/src/main.h b/src/main.h
index 49d18aad2..9371652d3 100644
--- a/src/main.h
+++ b/src/main.h
@@ -122,6 +122,14 @@ struct save_point {
};
+/**
+ * Union that would be used for storing sockaddrs
+ */
+union sa_union {
+ struct sockaddr_storage ss;
+ struct sockaddr_in s4;
+ struct sockaddr_in6 s6;
+};
/**
* Control session object
diff --git a/src/memcached.c b/src/memcached.c
index fc7152940..77078aa06 100644
--- a/src/memcached.c
+++ b/src/memcached.c
@@ -139,7 +139,9 @@ write_handler (int fd, short what, memcached_ctx_t * ctx)
iov[1].iov_len = ctx->param->bufsize - ctx->param->bufpos;
iov[2].iov_base = CRLF;
iov[2].iov_len = sizeof (CRLF) - 1;
- writev (ctx->sock, iov, 3);
+ if (writev (ctx->sock, iov, 3) == -1) {
+ memc_log (ctx, __LINE__, "memc_write: writev failed: %s", strerror (errno));
+ }
}
event_del (&ctx->mem_ev);
event_set (&ctx->mem_ev, ctx->sock, EV_READ | EV_PERSIST | EV_TIMEOUT, socket_callback, (void *)ctx);
diff --git a/src/plugins/custom/ipmark/ipmark.c b/src/plugins/custom/ipmark/ipmark.c
index 9bebcab22..f6d32b6ac 100644
--- a/src/plugins/custom/ipmark/ipmark.c
+++ b/src/plugins/custom/ipmark/ipmark.c
@@ -175,7 +175,7 @@ read_radix_file (void)
FILE *f;
char buf[BUFSIZ];
struct in_addr ina;
- int mask, value;
+ int mask = 0, value = 0;
f = fopen (filename, "r");
if (f != NULL) {
@@ -260,9 +260,9 @@ parse_line (const char *line, size_t len, char **output, void *user_data)
char *c = ip_buf, *err_str;
struct in_addr ina;
int state = 0, next_state = 0, dots = 0;
- int16_t value;
+ int16_t value = 0;
uint32_t mask;
- enum ipmark_command cmd;
+ enum ipmark_command cmd = COMMAND_ADD;
/* Parse input line */
p = line;
diff --git a/src/settings.c b/src/settings.c
index cd7167edd..dd4127c19 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -344,7 +344,7 @@ check_whitelist(struct worker_task *task, struct rspamd_settings *s)
gboolean
check_metric_settings (struct worker_task * task, struct metric * metric, double *score, double *rscore)
{
- struct rspamd_settings *us, *ds;
+ struct rspamd_settings *us = NULL, *ds = NULL;
double *sc, *rs;
*rscore = DEFAULT_REJECT_SCORE;
@@ -393,7 +393,7 @@ check_metric_settings (struct worker_task * task, struct metric * metric, double
gboolean
check_factor_settings (struct worker_task * task, const char *symbol, double *factor)
{
- struct rspamd_settings *us, *ds;
+ struct rspamd_settings *us = NULL, *ds = NULL;
double *fc;
if (check_setting (task, &us, &ds)) {
@@ -425,7 +425,7 @@ check_factor_settings (struct worker_task * task, const char *symbol, double *fa
gboolean
check_want_spam (struct worker_task * task)
{
- struct rspamd_settings *us, *ds;
+ struct rspamd_settings *us = NULL, *ds = NULL;
if (check_setting (task, &us, &ds)) {
if (us != NULL) {
diff --git a/src/smtp.c b/src/smtp.c
index 116089ee1..fc2811bed 100644
--- a/src/smtp.c
+++ b/src/smtp.c
@@ -326,14 +326,13 @@ static void
accept_socket (int fd, short what, void *arg)
{
struct rspamd_worker *worker = (struct rspamd_worker *)arg;
- struct sockaddr_storage ss;
- struct sockaddr_in *sin;
+ union sa_union su;
struct smtp_session *session;
- socklen_t addrlen = sizeof (ss);
+ socklen_t addrlen = sizeof (su.ss);
int nfd;
- if ((nfd = accept_from_socket (fd, (struct sockaddr *)&ss, &addrlen)) == -1) {
+ if ((nfd = accept_from_socket (fd, (struct sockaddr *)&su.ss, &addrlen)) == -1) {
msg_warn ("accept failed: %s", strerror (errno));
return;
}
@@ -345,14 +344,13 @@ accept_socket (int fd, short what, void *arg)
session = g_malloc (sizeof (struct smtp_session));
session->pool = memory_pool_new (memory_pool_get_size ());
- if (ss.ss_family == AF_UNIX) {
+ if (su.ss.ss_family == AF_UNIX) {
msg_info ("accepted connection from unix socket");
session->client_addr.s_addr = INADDR_NONE;
}
- else if (ss.ss_family == AF_INET) {
- sin = (struct sockaddr_in *)&ss;
- msg_info ("accepted connection from %s port %d", inet_ntoa (sin->sin_addr), ntohs (sin->sin_port));
- memcpy (&session->client_addr, &sin->sin_addr, sizeof (struct in_addr));
+ else if (su.ss.ss_family == AF_INET) {
+ msg_info ("accepted connection from %s port %d", inet_ntoa (su.s4.sin_addr), ntohs (su.s4.sin_port));
+ memcpy (&session->client_addr, &su.s4.sin_addr, sizeof (struct in_addr));
}
session->sock = nfd;
@@ -380,7 +378,7 @@ static void
parse_smtp_banner (struct smtp_worker_ctx *ctx, const char *line)
{
int hostmax, banner_len = sizeof ("220 ") - 1;
- char *p, *t, *hostbuf;
+ char *p, *t, *hostbuf = NULL;
gboolean has_crlf = FALSE;
p = (char *)line;
diff --git a/src/statfile.c b/src/statfile.c
index 005ea7c8a..08b271065 100644
--- a/src/statfile.c
+++ b/src/statfile.c
@@ -418,7 +418,7 @@ statfile_pool_create (statfile_pool_t * pool, char *filename, size_t size)
};
struct stat_file_block block = { 0, 0, 0 };
int fd;
- unsigned int buflen, nblocks;
+ unsigned int buflen = 0, nblocks;
char *buf = NULL;
if (statfile_pool_is_open (pool, filename) != NULL) {
diff --git a/src/symbols_cache.c b/src/symbols_cache.c
index f1589226a..a632152e4 100644
--- a/src/symbols_cache.c
+++ b/src/symbols_cache.c
@@ -525,7 +525,7 @@ call_symbol_callback (struct worker_task * task, struct symbols_cache * cache, g
{
struct timespec ts1, ts2;
uint64_t diff;
- struct cache_item *item;
+ struct cache_item *item = NULL;
struct symbol_callback_data *s = *save;
if (s == NULL) {
diff --git a/src/worker.c b/src/worker.c
index 115c3be11..5ebdaf84b 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -443,16 +443,15 @@ static void
accept_socket (int fd, short what, void *arg)
{
struct rspamd_worker *worker = (struct rspamd_worker *)arg;
- struct sockaddr_storage ss;
- struct sockaddr_in *sin;
+ union sa_union su;
struct worker_task *new_task;
GList *cur;
struct custom_filter *filt;
- socklen_t addrlen = sizeof (ss);
+ socklen_t addrlen = sizeof (su.ss);
int nfd;
- if ((nfd = accept_from_socket (fd, (struct sockaddr *)&ss, &addrlen)) == -1) {
+ if ((nfd = accept_from_socket (fd, (struct sockaddr *)&su.ss, &addrlen)) == -1) {
msg_warn ("accept failed: %s", strerror (errno));
return;
}
@@ -463,14 +462,13 @@ accept_socket (int fd, short what, void *arg)
new_task = construct_task (worker);
- if (ss.ss_family == AF_UNIX) {
+ if (su.ss.ss_family == AF_UNIX) {
msg_info ("accepted connection from unix socket");
new_task->client_addr.s_addr = INADDR_NONE;
}
- else if (ss.ss_family == AF_INET) {
- sin = (struct sockaddr_in *)&ss;
- msg_info ("accepted connection from %s port %d", inet_ntoa (sin->sin_addr), ntohs (sin->sin_port));
- memcpy (&new_task->client_addr, &sin->sin_addr, sizeof (struct in_addr));
+ else if (su.ss.ss_family == AF_INET) {
+ msg_info ("accepted connection from %s port %d", inet_ntoa (su.s4.sin_addr), ntohs (su.s4.sin_port));
+ memcpy (&new_task->client_addr, &su.s4.sin_addr, sizeof (struct in_addr));
}
new_task->sock = nfd;