X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fnetwork.c;h=5a8a88efe388317cd48288ad97e63412b8b6acef;hb=d26dd5c1db5c3310c9e69b2b910c6547469c99ce;hp=cd5c0c1231b72f26885e7ee78b4203a14a663346;hpb=291bb960600e67a8fd018f05231956fca91029eb;p=collectd.git diff --git a/src/network.c b/src/network.c index cd5c0c12..5a8a88ef 100644 --- a/src/network.c +++ b/src/network.c @@ -30,7 +30,6 @@ #include "common.h" #include "configfile.h" #include "utils_fbhash.h" -#include "utils_avltree.h" #include "utils_cache.h" #include "utils_complain.h" @@ -494,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 */ @@ -508,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_INIT_SECMEM) failed: %s", gcry_strerror (err)); + abort (); + } + gcry_control (GCRYCTL_INITIALIZATION_FINISHED); } /* }}} void network_init_gcrypt */ @@ -1213,7 +1227,7 @@ static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */ size_t buffer_offset; uint16_t username_len; part_encryption_aes256_t pea; - unsigned char hash[sizeof (pea.hash)]; + unsigned char hash[sizeof (pea.hash)] = { 0 }; gcry_cipher_hd_t cypher; gcry_error_t err; @@ -1300,7 +1314,6 @@ static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */ assert (buffer_offset == (part_size - payload_len)); /* Check hash sum */ - memset (hash, 0, sizeof (hash)); gcry_md_hash_buffer (GCRY_MD_SHA1, hash, buffer + buffer_offset, payload_len); if (memcmp (hash, pea.hash, sizeof (hash)) != 0) @@ -1381,7 +1394,7 @@ static int parse_packet (sockent_t *se, /* {{{ */ int status; value_list_t vl = VALUE_LIST_INIT; - notification_t n; + notification_t n = { 0 }; #if HAVE_LIBGCRYPT int packet_was_signed = (flags & PP_SIGNED); @@ -1391,7 +1404,6 @@ static int parse_packet (sockent_t *se, /* {{{ */ memset (&vl, '\0', sizeof (vl)); - memset (&n, '\0', sizeof (n)); status = 0; while ((status == 0) && (0 < buffer_size) @@ -1765,18 +1777,16 @@ static int network_set_interface (const sockent_t *se, const struct addrinfo *ai * index is preferred here, because of its similarity * to the way IPv6 handles this. Unfortunately, it * appears not to be portable. */ - struct ip_mreqn mreq; - - memset (&mreq, 0, sizeof (mreq)); - mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr; - mreq.imr_address.s_addr = ntohl (INADDR_ANY); - mreq.imr_ifindex = se->interface; + struct ip_mreqn mreq = { + .imr_multiaddr.s_addr = addr->sin_addr.s_addr, + .imr_address.s_addr = ntohl (INADDR_ANY), + .imr_ifindex = se->interface + }; #else - struct ip_mreq mreq; - - memset (&mreq, 0, sizeof (mreq)); - mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr; - mreq.imr_interface.s_addr = ntohl (INADDR_ANY); + struct ip_mreq mreq = { + .imr_multiaddr.s_addr = addr->sin_addr.s_addr, + .imr_interface.s_addr = ntohl (INADDR_ANY) + }; #endif if (setsockopt (se->data.client.fd, IPPROTO_IP, IP_MULTICAST_IF, @@ -2129,7 +2139,7 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ static c_complain_t complaint = C_COMPLAIN_INIT_STATIC; struct sockent_client *client; - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list = NULL, *ai_ptr; int status; _Bool reconnect = 0; @@ -2150,7 +2160,6 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ if (client->fd >= 0 && !reconnect) /* already connected and not stale*/ return (0); - memset (&ai_hints, 0, sizeof (ai_hints)); #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif @@ -2227,7 +2236,7 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ /* Open the file descriptors for a initialized sockent structure. */ static int sockent_server_listen (sockent_t *se) /* {{{ */ { - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_list, *ai_ptr; int status; @@ -2249,8 +2258,6 @@ static int sockent_server_listen (sockent_t *se) /* {{{ */ DEBUG ("network plugin: sockent_server_listen: node = %s; service = %s;", node, service); - memset (&ai_hints, 0, sizeof (ai_hints)); - ai_hints.ai_flags = 0; #ifdef AI_PASSIVE ai_hints.ai_flags |= AI_PASSIVE; #endif @@ -2625,7 +2632,6 @@ static void network_send_buffer_plain (sockent_t *se, /* {{{ */ static void network_send_buffer_signed (sockent_t *se, /* {{{ */ const char *in_buffer, size_t in_buffer_size) { - part_signature_sha256_t ps; char buffer[BUFF_SIG_SIZE + in_buffer_size]; size_t buffer_offset; size_t username_len; @@ -2667,9 +2673,10 @@ static void network_send_buffer_signed (sockent_t *se, /* {{{ */ in_buffer, in_buffer_size); /* Initialize the `ps' structure. */ - memset (&ps, 0, sizeof (ps)); - ps.head.type = htons (TYPE_SIGN_SHA256); - ps.head.length = htons (PART_SIGNATURE_SHA256_SIZE + username_len); + part_signature_sha256_t ps = { + .head.type = htons (TYPE_SIGN_SHA256), + .head.length = htons (PART_SIGNATURE_SHA256_SIZE + username_len) + }; /* Calculate the hash value. */ gcry_md_write (hd, buffer + PART_SIGNATURE_SHA256_SIZE, @@ -2702,7 +2709,6 @@ static void network_send_buffer_signed (sockent_t *se, /* {{{ */ static void network_send_buffer_encrypted (sockent_t *se, /* {{{ */ const char *in_buffer, size_t in_buffer_size) { - part_encryption_aes256_t pea; char buffer[BUFF_SIG_SIZE + in_buffer_size]; size_t buffer_size; size_t buffer_offset; @@ -2712,10 +2718,10 @@ static void network_send_buffer_encrypted (sockent_t *se, /* {{{ */ gcry_cipher_hd_t cypher; /* Initialize the header fields */ - memset (&pea, 0, sizeof (pea)); - pea.head.type = htons (TYPE_ENCR_AES256); - - pea.username = se->data.client.username; + part_encryption_aes256_t pea = { + .head.type = htons (TYPE_ENCR_AES256), + .username = se->data.client.username + }; username_len = strlen (pea.username); if ((PART_ENCRYPTION_AES256_SIZE + username_len) > BUFF_SIG_SIZE)