X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Flibcollectdclient%2Fnetwork_buffer.c;h=2c6277c856b24eb82dd319cf64a14c7798cad4d3;hb=1bdfcf9791729310f75857d0e002c40ef659a89b;hp=61c7c22e2d7ab963a2d98977f8c0c3747ad18723;hpb=c1219a1c9db2e8400e2ee94b87f86ccd441485d5;p=collectd.git diff --git a/src/libcollectdclient/network_buffer.c b/src/libcollectdclient/network_buffer.c index 61c7c22e..2c6277c8 100644 --- a/src/libcollectdclient/network_buffer.c +++ b/src/libcollectdclient/network_buffer.c @@ -1,6 +1,6 @@ /** * collectd - src/libcollectdclient/network_buffer.c - * Copyright (C) 2010-2012 Florian octo Forster + * Copyright (C) 2010-2015 Florian octo Forster * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -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); @@ -792,9 +789,9 @@ int lcc_network_buffer_finalize (lcc_network_buffer_t *nb) /* {{{ */ #if HAVE_LIBGCRYPT if (nb->seclevel == SIGN) - nb_add_signature (nb); + return nb_add_signature (nb); else if (nb->seclevel == ENCRYPT) - nb_add_encryption (nb); + return nb_add_encryption (nb); #endif return (0);