X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetwork.c;h=2296927dff1041b82056ea0132bcd94e8c994d88;hb=21ab7512825cf8177d5eee5101344b45d0854610;hp=bf1f2ab6069f61a93443e607ef6821571b5691e3;hpb=12f249b209d7fa31e3a9d53315e47a2342463e0f;p=collectd.git diff --git a/src/network.c b/src/network.c index bf1f2ab6..2296927d 100644 --- a/src/network.c +++ b/src/network.c @@ -30,15 +30,11 @@ #include "common.h" #include "configfile.h" #include "utils_fbhash.h" -#include "utils_avltree.h" #include "utils_cache.h" #include "utils_complain.h" #include "network.h" -#if HAVE_PTHREAD_H -# include -#endif #if HAVE_NETDB_H # include #endif @@ -56,7 +52,6 @@ #endif #if HAVE_LIBGCRYPT -# include # if defined __APPLE__ /* default xcode compiler throws warnings even when deprecated functionality * is not used. -Werror breaks the build because of erroneous warnings. @@ -414,10 +409,10 @@ static int network_dispatch_values (value_list_t *vl, /* {{{ */ { int status; - if ((vl->time <= 0) - || (strlen (vl->host) <= 0) - || (strlen (vl->plugin) <= 0) - || (strlen (vl->type) <= 0)) + if ((vl->time == 0) + || (strlen (vl->host) == 0) + || (strlen (vl->plugin) == 0) + || (strlen (vl->type) == 0)) return (-EINVAL); if (!check_receive_okay (vl)) @@ -498,6 +493,8 @@ static int network_dispatch_notification (notification_t *n) /* {{{ */ #if HAVE_LIBGCRYPT static void network_init_gcrypt (void) /* {{{ */ { + gcry_error_t err; + /* http://lists.gnupg.org/pipermail/gcrypt-devel/2003-August/000458.html * Because you can't know in a library whether another library has * already initialized the library */ @@ -512,10 +509,23 @@ static void network_init_gcrypt (void) /* {{{ */ * * tl;dr: keep all these gry_* statements in this exact order please. */ # if GCRYPT_VERSION_NUMBER < 0x010600 - gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); + err = gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); + if (err) + { + ERROR ("network plugin: gcry_control (GCRYCTL_SET_THREAD_CBS) failed: %s", gcry_strerror (err)); + abort (); + } # endif + gcry_check_version (NULL); - gcry_control (GCRYCTL_INIT_SECMEM, 32768); + + err = gcry_control (GCRYCTL_INIT_SECMEM, 32768); + if (err) + { + ERROR ("network plugin: gcry_control (GCRYCTL_SET_THREAD_CBS) failed: %s", gcry_strerror (err)); + abort (); + } + gcry_control (GCRYCTL_INITIALIZATION_FINISHED); } /* }}} void network_init_gcrypt */ @@ -1250,7 +1260,7 @@ static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */ BUFFER_READ (&username_len, sizeof (username_len)); username_len = ntohs (username_len); - if ((username_len <= 0) + if ((username_len == 0) || (username_len > (part_size - (PART_ENCRYPTION_AES256_SIZE + 1)))) { NOTICE ("network plugin: parse_part_encr_aes256: " @@ -1443,6 +1453,7 @@ static int parse_packet (sockent_t *se, /* {{{ */ printed_ignore_warning = 1; } buffer = ((char *) buffer) + pkg_length; + buffer_size -= (size_t) pkg_length; continue; } #endif /* HAVE_LIBGCRYPT */ @@ -1470,6 +1481,7 @@ static int parse_packet (sockent_t *se, /* {{{ */ printed_ignore_warning = 1; } buffer = ((char *) buffer) + pkg_length; + buffer_size -= (size_t) pkg_length; continue; } #endif /* HAVE_LIBGCRYPT */ @@ -1581,13 +1593,13 @@ static int parse_packet (sockent_t *se, /* {{{ */ "unknown severity %i.", n.severity); } - else if (n.time <= 0) + else if (n.time == 0) { INFO ("network plugin: " "Ignoring notification with " "time == 0."); } - else if (strlen (n.message) <= 0) + else if (strlen (n.message) == 0) { INFO ("network plugin: " "Ignoring notification with " @@ -1611,6 +1623,7 @@ static int parse_packet (sockent_t *se, /* {{{ */ DEBUG ("network plugin: parse_packet: Unknown part" " type: 0x%04hx", pkg_type); buffer = ((char *) buffer) + pkg_length; + buffer_size -= (size_t) pkg_length; } } /* while (buffer_size > sizeof (part_header_t)) */