diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-02-09 16:43:40 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-02-09 16:43:40 +0000 |
commit | c2cbcd8d98ae8e1b8d1ef06bc6dc53f77ac3bd16 (patch) | |
tree | e8742046ad3eac446a64576f9bfd605e583e9ee5 /src/libutil | |
parent | dcbe3146b882a731e1cd82025607bd423bb82024 (diff) | |
download | rspamd-c2cbcd8d98ae8e1b8d1ef06bc6dc53f77ac3bd16.tar.gz rspamd-c2cbcd8d98ae8e1b8d1ef06bc6dc53f77ac3bd16.zip |
Fix some issues found by coverity
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/addr.c | 6 | ||||
-rw-r--r-- | src/libutil/http.c | 1 | ||||
-rw-r--r-- | src/libutil/map.c | 2 | ||||
-rw-r--r-- | src/libutil/sqlite_utils.c | 9 | ||||
-rw-r--r-- | src/libutil/str_util.c | 2 | ||||
-rw-r--r-- | src/libutil/util.c | 70 |
6 files changed, 61 insertions, 29 deletions
diff --git a/src/libutil/addr.c b/src/libutil/addr.c index b70de6b9d..e95ac4c64 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -760,16 +760,16 @@ rspamd_inet_address_listen (const rspamd_inet_addr_t *addr, gint type, sa = &addr->u.in.addr.sa; } - setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof (gint)); + (void)setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof (gint)); #ifdef HAVE_IPV6_V6ONLY if (addr->af == AF_INET6) { /* We need to set this flag to avoid errors */ on = 1; #ifdef SOL_IPV6 - setsockopt (fd, SOL_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint)); + (void)setsockopt (fd, SOL_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint)); #elif defined(IPPROTO_IPV6) - setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint)); + (void)setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint)); #endif } #endif diff --git a/src/libutil/http.c b/src/libutil/http.c index 605439129..21b763108 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -723,6 +723,7 @@ rspamd_http_decrypt_message (struct rspamd_http_connection *conn, msg->body_buf.len = 0; + memset (&decrypted_parser, 0, sizeof (decrypted_parser)); http_parser_init (&decrypted_parser, conn->type == RSPAMD_HTTP_SERVER ? HTTP_REQUEST : HTTP_RESPONSE); diff --git a/src/libutil/map.c b/src/libutil/map.c index 8d04fe236..ea5f3f210 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -802,7 +802,7 @@ rspamd_parse_abstract_list (rspamd_mempool_t * pool, c = p; data->state = 1; } - else if (*p == '\r' || *p == '\n') { + else if ((*p == '\r' || *p == '\n') && p > c) { /* Got EOL marker, save stored string */ s = strip_map_elt (pool, c, p - c); diff --git a/src/libutil/sqlite_utils.c b/src/libutil/sqlite_utils.c index 7e80190e3..883d26580 100644 --- a/src/libutil/sqlite_utils.c +++ b/src/libutil/sqlite_utils.c @@ -337,6 +337,13 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const path, rc); #endif + if (has_lock && lock_fd != -1) { + msg_debug_pool_check ("removing lock from %s", lock_path); + rspamd_file_unlock (lock_fd, FALSE); + unlink (lock_path); + close (lock_fd); + } + return NULL; } @@ -418,7 +425,7 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const sqlite3_errmsg (sqlite)); } - if (has_lock) { + if (has_lock && lock_fd != -1) { msg_debug_pool_check ("removing lock from %s", lock_path); rspamd_file_unlock (lock_fd, FALSE); unlink (lock_path); diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index 6daf83993..89a6537de 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -1382,7 +1382,7 @@ gint rspamd_decode_hex_buf (const gchar *in, gsize inlen, guchar *out, gsize outlen) { - guchar *o, *end, ret; + guchar *o, *end, ret = 0; const gchar *p; gchar c; diff --git a/src/libutil/util.c b/src/libutil/util.c index 19ae980c0..e715c97cf 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -173,18 +173,25 @@ rspamd_inet_socket_create (gint type, struct addrinfo *addr, gboolean is_server, } if (is_server) { - setsockopt (fd, - SOL_SOCKET, - SO_REUSEADDR, - (const void *)&on, - sizeof (gint)); + if (setsockopt (fd, + SOL_SOCKET, + SO_REUSEADDR, + (const void *)&on, + sizeof (gint)) == -1) { + msg_warn ("setsockopt failed: %d, '%s'", errno, + strerror (errno)); + } #ifdef HAVE_IPV6_V6ONLY if (cur->ai_family == AF_INET6) { - setsockopt (fd, - IPPROTO_IPV6, - IPV6_V6ONLY, - (const void *)&on, - sizeof (gint)); + if (setsockopt (fd, + IPPROTO_IPV6, + IPV6_V6ONLY, + (const void *)&on, + sizeof (gint)) == -1) { + + msg_warn ("setsockopt failed: %d, '%s'", errno, + strerror (errno)); + } } #endif r = bind (fd, cur->ai_addr, cur->ai_addrlen); @@ -218,10 +225,12 @@ rspamd_inet_socket_create (gint type, struct addrinfo *addr, gboolean is_server, else { /* Still need to check SO_ERROR on socket */ optlen = sizeof (s_error); - getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen); - if (s_error) { - errno = s_error; - goto out; + + if (getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen) != -1) { + if (s_error) { + errno = s_error; + goto out; + } } } if (list == NULL) { @@ -314,8 +323,12 @@ rspamd_socket_unix (const gchar *path, goto out; } if (is_server) { - setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, - sizeof (gint)); + if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, + sizeof (gint)) == -1) { + msg_warn ("setsockopt failed: %d, '%s'", errno, + strerror (errno)); + } + r = bind (fd, (struct sockaddr *)addr, SUN_LEN (addr)); } else { @@ -348,10 +361,12 @@ rspamd_socket_unix (const gchar *path, else { /* Still need to check SO_ERROR on socket */ optlen = sizeof (s_error); - getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen); - if (s_error) { - errno = s_error; - goto out; + + if (getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen) != -1) { + if (s_error) { + errno = s_error; + goto out; + } } } @@ -496,6 +511,7 @@ rspamd_sockets_list (const gchar *credits, guint16 port, } if (fd != -1) { result = g_list_prepend (result, GINT_TO_POINTER (fd)); + fd = -1; } else { goto err; @@ -1747,12 +1763,20 @@ restart: /* Turn echo off */ if (tcgetattr (input, &oterm) != 0) { + close (input); errno = ENOTTY; return 0; } + memcpy (&term, &oterm, sizeof(term)); term.c_lflag &= ~(ECHO | ECHONL); - (void)tcsetattr (input, TCSAFLUSH, &term); + + if (tcsetattr (input, TCSAFLUSH, &term) == -1) { + errno = ENOTTY; + close (input); + return 0; + } + (void)write (output, "Enter passphrase: ", sizeof ("Enter passphrase: ") - 1); @@ -1816,7 +1840,7 @@ restart: } } - return p - buf; + return (p - buf); #endif } @@ -1942,7 +1966,7 @@ rspamd_init_libs (void) OTTERY_ENTROPY_SRC_RDRAND); } - ottery_init (ottery_cfg); + g_assert (ottery_init (ottery_cfg) == 0); #ifdef HAVE_LOCALE_H if (getenv ("LANG") == NULL) { |