X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flibcollectdclient%2Fnetwork_buffer.c;h=2c6277c856b24eb82dd319cf64a14c7798cad4d3;hb=88ad924df0622911c555cea6826933732e91d9cd;hp=343c285ad9ec35e95fcdcce23420d84b05a959de;hpb=2c7b491427fd84c9e24c9d41686a15ce42219a0b;p=collectd.git diff --git a/src/libcollectdclient/network_buffer.c b/src/libcollectdclient/network_buffer.c index 343c285a..2c6277c8 100644 --- a/src/libcollectdclient/network_buffer.c +++ b/src/libcollectdclient/network_buffer.c @@ -36,7 +36,6 @@ #include #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. @@ -134,13 +133,16 @@ static _Bool have_gcrypt (void) /* {{{ */ #if HAVE_LIBGCRYPT # if GCRYPT_VERSION_NUMBER < 0x010600 - gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); + if (gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread)) + return (0); # endif if (!gcry_check_version (GCRYPT_VERSION)) return (0); - gcry_control (GCRYCTL_INIT_SECMEM, 32768, 0); + if (!gcry_control (GCRYCTL_INIT_SECMEM, 32768, 0)) + return (0); + gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); result = 1; @@ -272,7 +274,6 @@ static int nb_add_values (char **ret_buffer, /* {{{ */ value_t pkg_values[vl->values_len]; size_t offset; - size_t i; packet_len = sizeof (pkg_type) + sizeof (pkg_length) + sizeof (pkg_num_values) @@ -286,7 +287,7 @@ static int nb_add_values (char **ret_buffer, /* {{{ */ pkg_length = htons ((uint16_t) packet_len); pkg_num_values = htons ((uint16_t) vl->values_len); - for (i = 0; i < vl->values_len; i++) + for (size_t i = 0; i < vl->values_len; i++) { pkg_values_types[i] = (uint8_t) vl->values_types[i]; switch (vl->values_types[i]) @@ -651,19 +652,17 @@ lcc_network_buffer_t *lcc_network_buffer_create (size_t size) /* {{{ */ return (NULL); } - nb = malloc (sizeof (*nb)); + nb = calloc (1, sizeof (*nb)); if (nb == NULL) return (NULL); - memset (nb, 0, sizeof (*nb)); nb->size = size; - nb->buffer = malloc (nb->size); + nb->buffer = calloc (1, nb->size); if (nb->buffer == NULL) { free (nb); return (NULL); } - memset (nb->buffer, 0, nb->size); nb->ptr = nb->buffer; nb->free = nb->size; @@ -761,7 +760,8 @@ int lcc_network_buffer_initialize (lcc_network_buffer_t *nb) /* {{{ */ uint16_t pkg_type = htons (TYPE_ENCR_AES256); uint16_t pkg_length = 0; /* Filled in in finalize. */ uint16_t pkg_user_len = htons ((uint16_t) username_length); - char hash[20]; + /* Filled in in finalize. */ + char hash[20] = { 0 }; nb->encr_header_len = username_length; nb->encr_header_len += PART_ENCRYPTION_AES256_SIZE; @@ -769,9 +769,6 @@ int lcc_network_buffer_initialize (lcc_network_buffer_t *nb) /* {{{ */ gcry_randomize ((void *) &nb->encr_iv, sizeof (nb->encr_iv), GCRY_STRONG_RANDOM); - /* Filled in in finalize. */ - memset (hash, 0, sizeof (hash)); - ADD_STATIC (nb, pkg_type); ADD_STATIC (nb, pkg_length); ADD_STATIC (nb, pkg_user_len);