X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetwork.c;h=c6845eb9696198cc068e88686fb439e82bfc9df6;hb=7bfda8d327240ac73297e4449663814dd0594be5;hp=af24911ee365b1ae512000cce93103ffdaf86a94;hpb=add25ce6f3129cb7138e96e5f55d11de1e5cf6de;p=collectd.git diff --git a/src/network.c b/src/network.c index af24911e..c6845eb9 100644 --- a/src/network.c +++ b/src/network.c @@ -498,13 +498,15 @@ static int network_dispatch_notification (notification_t *n) /* {{{ */ } /* }}} int network_dispatch_notification */ #if HAVE_LIBGCRYPT -static void network_init_gcrypt (void) /* {{{ */ +static int 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 */ if (gcry_control (GCRYCTL_ANY_INITIALIZATION_P)) - return; + return (0); /* http://www.gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html * To ensure thread-safety, it's important to set GCRYCTL_SET_THREAD_CBS @@ -514,12 +516,26 @@ 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)); + return (-1); + } # 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_INIT_SECMEM) failed: %s", gcry_strerror (err)); + return (-1); + } + gcry_control (GCRYCTL_INITIALIZATION_FINISHED); -} /* }}} void network_init_gcrypt */ + return (0); +} /* }}} int network_init_gcrypt */ static gcry_cipher_hd_t network_get_aes256_cypher (sockent_t *se, /* {{{ */ const void *iv, size_t iv_size, const char *username) @@ -1444,6 +1460,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 */ @@ -1471,6 +1488,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 */ @@ -1612,6 +1630,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)) */ @@ -2059,7 +2078,12 @@ static int sockent_init_crypto (sockent_t *se) /* {{{ */ { if (se->data.client.security_level > SECURITY_LEVEL_NONE) { - network_init_gcrypt (); + if (network_init_gcrypt () < 0) + { + ERROR ("network plugin: Cannot configure client socket with " + "security: Failed to initialize crypto library."); + return (-1); + } if ((se->data.client.username == NULL) || (se->data.client.password == NULL)) @@ -2079,7 +2103,12 @@ static int sockent_init_crypto (sockent_t *se) /* {{{ */ { if (se->data.server.security_level > SECURITY_LEVEL_NONE) { - network_init_gcrypt (); + if (network_init_gcrypt () < 0) + { + ERROR ("network plugin: Cannot configure server socket with " + "security: Failed to initialize crypto library."); + return (-1); + } if (se->data.server.auth_file == NULL) { @@ -2891,6 +2920,11 @@ static int network_write (const data_set_t *ds, const value_list_t *vl, { int status; + /* listen_loop is set to non-zero in the shutdown callback, which is + * guaranteed to be called *after* all the write threads have been shut + * down. */ + assert (listen_loop == 0); + if (!check_send_okay (vl)) { #if COLLECT_DEBUG @@ -3530,7 +3564,11 @@ static int network_init (void) have_init = 1; #if HAVE_LIBGCRYPT - network_init_gcrypt (); + if (network_init_gcrypt () < 0) + { + ERROR ("network plugin: Failed to initialize crypto library."); + return (-1); + } #endif if (network_config_stats != 0)