Browse Source

* Fix strict aliasing while compiling with optimization

* Fix tanhl detection for platforms that have not implementation of it
* Remove several compile warnings
rspamd-0.5
Vsevolod Stakhov 16 years ago
parent
commit
0612e84b3c
  1. 1
      CMakeLists.txt
  2. 2
      config.h.in
  3. 8
      src/cfg_utils.c
  4. 17
      src/cfg_xml.c
  5. 2
      src/classifiers/winnow.c
  6. 2
      src/evdns/CMakeLists.txt
  7. 3
      src/expressions.c
  8. 16
      src/lmtp.c
  9. 5
      src/logger.c
  10. 8
      src/main.h
  11. 4
      src/memcached.c
  12. 6
      src/plugins/custom/ipmark/ipmark.c
  13. 6
      src/settings.c
  14. 18
      src/smtp.c
  15. 2
      src/statfile.c
  16. 2
      src/symbols_cache.c
  17. 16
      src/worker.c

1
CMakeLists.txt

@ -280,6 +280,7 @@ CHECK_FUNCTION_EXISTS(vfork HAVE_VFORK)
CHECK_FUNCTION_EXISTS(wait4 HAVE_WAIT4) CHECK_FUNCTION_EXISTS(wait4 HAVE_WAIT4)
CHECK_FUNCTION_EXISTS(waitpid HAVE_WAITPID) CHECK_FUNCTION_EXISTS(waitpid HAVE_WAITPID)
CHECK_FUNCTION_EXISTS(flock HAVE_FLOCK) 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(PATH_MAX limits.h HAVE_PATH_MAX)
CHECK_SYMBOL_EXISTS(MAXPATHLEN sys/param.h HAVE_MAXPATHLEN) CHECK_SYMBOL_EXISTS(MAXPATHLEN sys/param.h HAVE_MAXPATHLEN)

2
config.h.in

@ -96,6 +96,8 @@
#cmakedefine HAVE_FLOCK 1 #cmakedefine HAVE_FLOCK 1
#cmakedefine HAVE_TANHL 1
#cmakedefine HAVE_SA_SIGINFO 1 #cmakedefine HAVE_SA_SIGINFO 1
#cmakedefine DEBUG_MODE 1 #cmakedefine DEBUG_MODE 1

8
src/cfg_utils.c

@ -727,7 +727,15 @@ internal_normalizer_func (struct config_file *cfg, long double score, void *data
return score; return score;
} }
else { else {
#ifdef HAVE_TANHL
return max * tanhl (score / max); 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; return score;

17
src/cfg_xml.c

@ -744,11 +744,12 @@ handle_lua (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GHashTable
lua_file = basename (tmp2); lua_file = basename (tmp2);
if (lua_dir && lua_file) { if (lua_dir && lua_file) {
cur_dir = g_malloc (PATH_MAX); 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) { if (luaL_dofile (L, lua_file) != 0) {
msg_err ("cannot load lua file %s: %s", val, lua_tostring (L, -1)); 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 (cur_dir);
g_free (tmp1); g_free (tmp1);
g_free (tmp2); g_free (tmp2);
@ -757,14 +758,18 @@ handle_lua (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GHashTable
} }
else { else {
msg_err ("cannot chdir to %s: %s", lua_dir, strerror (errno));; 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 (cur_dir);
g_free (tmp1); g_free (tmp1);
g_free (tmp2); g_free (tmp2);
return FALSE; 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 (cur_dir);
g_free (tmp1); g_free (tmp1);
g_free (tmp2); 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); cfg->script_modules = g_list_prepend (cfg->script_modules, cur);
} }
globfree (&globbuf); globfree (&globbuf);
g_free (pattern);
} }
else { else {
msg_err ("glob failed: %s", strerror (errno)); msg_err ("glob failed: %s", strerror (errno));
g_free (pattern);
return FALSE; return FALSE;
} }
} }

2
src/classifiers/winnow.c

@ -335,7 +335,7 @@ winnow_learn (struct classifier_ctx *ctx, statfile_pool_t *pool, stat_file_t *fi
char *value; char *value;
int nodes, minnodes, iterations = 0; int nodes, minnodes, iterations = 0;
struct statfile *st; struct statfile *st;
stat_file_t *sel;
stat_file_t *sel = NULL;
long double res = 0., max = 0.; long double res = 0., max = 0.;
GList *cur; GList *cur;

2
src/evdns/CMakeLists.txt

@ -2,4 +2,4 @@
SET(EVDNSSRC evdns.c) SET(EVDNSSRC evdns.c)
ADD_LIBRARY(rspamd_evdns STATIC ${EVDNSSRC}) 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")

3
src/expressions.c

@ -1306,9 +1306,10 @@ is_recipient_list_sorted (const InternetAddressList * ia)
return FALSE; return FALSE;
} }
#ifdef GMIME24 #ifdef GMIME24
num = internet_address_list_length ((InternetAddressList *)ia);
cur = ia; cur = ia;
for (i = 0; i < num; i ++) { 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); current.addr = (char *)internet_address_get_name (addr);
if (previous.addr != NULL) { if (previous.addr != NULL) {
if (g_ascii_strcasecmp (current.addr, previous.addr) < 0) { if (g_ascii_strcasecmp (current.addr, previous.addr) < 0) {

16
src/lmtp.c

@ -224,14 +224,13 @@ static void
accept_socket (int fd, short what, void *arg) accept_socket (int fd, short what, void *arg)
{ {
struct rspamd_worker *worker = (struct rspamd_worker *)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 worker_task *new_task;
struct rspamd_lmtp_proto *lmtp; struct rspamd_lmtp_proto *lmtp;
socklen_t addrlen = sizeof (ss);
socklen_t addrlen = sizeof (su.ss);
int nfd; 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)); msg_warn ("accept failed: %s", strerror (errno));
return; return;
} }
@ -240,14 +239,13 @@ accept_socket (int fd, short what, void *arg)
new_task = construct_task (worker); 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"); msg_info ("accepted connection from unix socket");
new_task->client_addr.s_addr = INADDR_NONE; 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; new_task->sock = nfd;

5
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) { else if (errno == EFAULT || errno == EINVAL || errno == EFBIG || errno == ENOSPC) {
/* Rare case */ /* 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) { else if (errno == EPIPE) {
/* We write to some pipe and it disappears, disable logging */ /* We write to some pipe and it disappears, disable logging */

8
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 * Control session object

4
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[1].iov_len = ctx->param->bufsize - ctx->param->bufpos;
iov[2].iov_base = CRLF; iov[2].iov_base = CRLF;
iov[2].iov_len = sizeof (CRLF) - 1; 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_del (&ctx->mem_ev);
event_set (&ctx->mem_ev, ctx->sock, EV_READ | EV_PERSIST | EV_TIMEOUT, socket_callback, (void *)ctx); event_set (&ctx->mem_ev, ctx->sock, EV_READ | EV_PERSIST | EV_TIMEOUT, socket_callback, (void *)ctx);

6
src/plugins/custom/ipmark/ipmark.c

@ -175,7 +175,7 @@ read_radix_file (void)
FILE *f; FILE *f;
char buf[BUFSIZ]; char buf[BUFSIZ];
struct in_addr ina; struct in_addr ina;
int mask, value;
int mask = 0, value = 0;
f = fopen (filename, "r"); f = fopen (filename, "r");
if (f != NULL) { 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; char *c = ip_buf, *err_str;
struct in_addr ina; struct in_addr ina;
int state = 0, next_state = 0, dots = 0; int state = 0, next_state = 0, dots = 0;
int16_t value;
int16_t value = 0;
uint32_t mask; uint32_t mask;
enum ipmark_command cmd;
enum ipmark_command cmd = COMMAND_ADD;
/* Parse input line */ /* Parse input line */
p = line; p = line;

6
src/settings.c

@ -344,7 +344,7 @@ check_whitelist(struct worker_task *task, struct rspamd_settings *s)
gboolean gboolean
check_metric_settings (struct worker_task * task, struct metric * metric, double *score, double *rscore) 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; double *sc, *rs;
*rscore = DEFAULT_REJECT_SCORE; *rscore = DEFAULT_REJECT_SCORE;
@ -393,7 +393,7 @@ check_metric_settings (struct worker_task * task, struct metric * metric, double
gboolean gboolean
check_factor_settings (struct worker_task * task, const char *symbol, double *factor) 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; double *fc;
if (check_setting (task, &us, &ds)) { if (check_setting (task, &us, &ds)) {
@ -425,7 +425,7 @@ check_factor_settings (struct worker_task * task, const char *symbol, double *fa
gboolean gboolean
check_want_spam (struct worker_task * task) 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 (check_setting (task, &us, &ds)) {
if (us != NULL) { if (us != NULL) {

18
src/smtp.c

@ -326,14 +326,13 @@ static void
accept_socket (int fd, short what, void *arg) accept_socket (int fd, short what, void *arg)
{ {
struct rspamd_worker *worker = (struct rspamd_worker *)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; struct smtp_session *session;
socklen_t addrlen = sizeof (ss);
socklen_t addrlen = sizeof (su.ss);
int nfd; 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)); msg_warn ("accept failed: %s", strerror (errno));
return; return;
} }
@ -345,14 +344,13 @@ accept_socket (int fd, short what, void *arg)
session = g_malloc (sizeof (struct smtp_session)); session = g_malloc (sizeof (struct smtp_session));
session->pool = memory_pool_new (memory_pool_get_size ()); 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"); msg_info ("accepted connection from unix socket");
session->client_addr.s_addr = INADDR_NONE; 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; session->sock = nfd;
@ -380,7 +378,7 @@ static void
parse_smtp_banner (struct smtp_worker_ctx *ctx, const char *line) parse_smtp_banner (struct smtp_worker_ctx *ctx, const char *line)
{ {
int hostmax, banner_len = sizeof ("220 ") - 1; int hostmax, banner_len = sizeof ("220 ") - 1;
char *p, *t, *hostbuf;
char *p, *t, *hostbuf = NULL;
gboolean has_crlf = FALSE; gboolean has_crlf = FALSE;
p = (char *)line; p = (char *)line;

2
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 }; struct stat_file_block block = { 0, 0, 0 };
int fd; int fd;
unsigned int buflen, nblocks;
unsigned int buflen = 0, nblocks;
char *buf = NULL; char *buf = NULL;
if (statfile_pool_is_open (pool, filename) != NULL) { if (statfile_pool_is_open (pool, filename) != NULL) {

2
src/symbols_cache.c

@ -525,7 +525,7 @@ call_symbol_callback (struct worker_task * task, struct symbols_cache * cache, g
{ {
struct timespec ts1, ts2; struct timespec ts1, ts2;
uint64_t diff; uint64_t diff;
struct cache_item *item;
struct cache_item *item = NULL;
struct symbol_callback_data *s = *save; struct symbol_callback_data *s = *save;
if (s == NULL) { if (s == NULL) {

16
src/worker.c

@ -443,16 +443,15 @@ static void
accept_socket (int fd, short what, void *arg) accept_socket (int fd, short what, void *arg)
{ {
struct rspamd_worker *worker = (struct rspamd_worker *)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 worker_task *new_task;
GList *cur; GList *cur;
struct custom_filter *filt; struct custom_filter *filt;
socklen_t addrlen = sizeof (ss);
socklen_t addrlen = sizeof (su.ss);
int nfd; 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)); msg_warn ("accept failed: %s", strerror (errno));
return; return;
} }
@ -463,14 +462,13 @@ accept_socket (int fd, short what, void *arg)
new_task = construct_task (worker); 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"); msg_info ("accepted connection from unix socket");
new_task->client_addr.s_addr = INADDR_NONE; 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; new_task->sock = nfd;

Loading…
Cancel
Save