X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetwork.c;h=bf1f2ab6069f61a93443e607ef6821571b5691e3;hb=72a76347831a848e6722d9147297a1e03c4c01d8;hp=439b0cef704d7d22404f73561faf4d2b3241729c;hpb=a82395b57384541152423862bcf44c0db7789641;p=collectd.git diff --git a/src/network.c b/src/network.c index 439b0cef..bf1f2ab6 100644 --- a/src/network.c +++ b/src/network.c @@ -618,14 +618,14 @@ static int write_part_values (char **ret_buffer, int *ret_buffer_len, if (*ret_buffer_len < packet_len) return (-1); - pkg_values_types = (uint8_t *) malloc (num_values * sizeof (uint8_t)); + pkg_values_types = malloc (num_values * sizeof (*pkg_values_types)); if (pkg_values_types == NULL) { ERROR ("network plugin: write_part_values: malloc failed."); return (-1); } - pkg_values = (value_t *) malloc (num_values * sizeof (value_t)); + pkg_values = malloc (num_values * sizeof (*pkg_values)); if (pkg_values == NULL) { free (pkg_values_types); @@ -934,7 +934,7 @@ static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len, uint16_t pkg_length; size_t payload_size; - if (output_len <= 0) + if (output_len == 0) return (EINVAL); if (buffer_len < header_size) @@ -1369,7 +1369,7 @@ static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */ warning_has_been_printed = 1; } - *ret_buffer += ph_length; + *ret_buffer = (void *) (((char *) *ret_buffer) + ph_length); *ret_buffer_size -= ph_length; return (0); @@ -1408,7 +1408,7 @@ static int parse_packet (sockent_t *se, /* {{{ */ (void *) buffer, sizeof (pkg_type)); memcpy ((void *) &pkg_length, - (void *) (buffer + sizeof (pkg_type)), + (void *) (((char *) buffer) + sizeof (pkg_type)), sizeof (pkg_length)); pkg_length = ntohs (pkg_length); @@ -2012,10 +2012,9 @@ static sockent_t *sockent_create (int type) /* {{{ */ if ((type != SOCKENT_TYPE_CLIENT) && (type != SOCKENT_TYPE_SERVER)) return (NULL); - se = malloc (sizeof (*se)); + se = calloc (1, sizeof (*se)); if (se == NULL) return (NULL); - memset (se, 0, sizeof (*se)); se->type = type; se->node = NULL; @@ -2196,16 +2195,15 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ continue; } - client->addr = malloc (sizeof (*client->addr)); + client->addr = calloc (1, sizeof (*client->addr)); if (client->addr == NULL) { - ERROR ("network plugin: malloc failed."); + ERROR ("network plugin: calloc failed."); close (client->fd); client->fd = -1; continue; } - memset (client->addr, 0, sizeof (*client->addr)); assert (sizeof (*client->addr) >= ai_ptr->ai_addrlen); memcpy (client->addr, ai_ptr->ai_addr, ai_ptr->ai_addrlen); client->addrlen = ai_ptr->ai_addrlen; @@ -2313,7 +2311,7 @@ static int sockent_server_listen (sockent_t *se) /* {{{ */ freeaddrinfo (ai_list); - if (se->data.server.fd_num <= 0) + if (se->data.server.fd_num == 0) return (-1); return (0); } /* }}} int sockent_server_listen */ @@ -2495,14 +2493,14 @@ static int network_receive (void) /* {{{ */ * these entries in the dispatch thread but put them in * another list, so we don't have to allocate more and * more of these structures. */ - ent = malloc (sizeof (receive_list_entry_t)); + ent = calloc (1, sizeof (*ent)); if (ent == NULL) { - ERROR ("network plugin: malloc failed."); + ERROR ("network plugin: calloc failed."); status = ENOMEM; break; } - memset (ent, 0, sizeof (receive_list_entry_t)); + ent->data = malloc (network_config_packet_size); if (ent->data == NULL) { @@ -2587,7 +2585,7 @@ static void network_init_buffer (void) memset (&send_buffer_vl, 0, sizeof (send_buffer_vl)); } /* int network_init_buffer */ -static void networt_send_buffer_plain (sockent_t *se, /* {{{ */ +static void network_send_buffer_plain (sockent_t *se, /* {{{ */ const char *buffer, size_t buffer_size) { int status; @@ -2617,7 +2615,7 @@ static void networt_send_buffer_plain (sockent_t *se, /* {{{ */ break; } /* while (42) */ -} /* }}} void networt_send_buffer_plain */ +} /* }}} void network_send_buffer_plain */ #if HAVE_LIBGCRYPT #define BUFFER_ADD(p,s) do { \ @@ -2625,7 +2623,7 @@ static void networt_send_buffer_plain (sockent_t *se, /* {{{ */ buffer_offset += (s); \ } while (0) -static void networt_send_buffer_signed (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; @@ -2699,10 +2697,10 @@ static void networt_send_buffer_signed (sockent_t *se, /* {{{ */ hd = NULL; buffer_offset = PART_SIGNATURE_SHA256_SIZE + username_len + in_buffer_size; - networt_send_buffer_plain (se, buffer, buffer_offset); -} /* }}} void networt_send_buffer_signed */ + network_send_buffer_plain (se, buffer, buffer_offset); +} /* }}} void network_send_buffer_signed */ -static void networt_send_buffer_encrypted (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; @@ -2732,7 +2730,7 @@ static void networt_send_buffer_encrypted (sockent_t *se, /* {{{ */ - sizeof (pea.hash); assert (buffer_size <= sizeof (buffer)); - DEBUG ("network plugin: networt_send_buffer_encrypted: " + DEBUG ("network plugin: network_send_buffer_encrypted: " "buffer_size = %zu;", buffer_size); pea.head.length = htons ((uint16_t) (PART_ENCRYPTION_AES256_SIZE @@ -2779,8 +2777,8 @@ static void networt_send_buffer_encrypted (sockent_t *se, /* {{{ */ } /* Send it out without further modifications */ - networt_send_buffer_plain (se, buffer, buffer_size); -} /* }}} void networt_send_buffer_encrypted */ + network_send_buffer_plain (se, buffer, buffer_size); +} /* }}} void network_send_buffer_encrypted */ #undef BUFFER_ADD #endif /* HAVE_LIBGCRYPT */ @@ -2794,12 +2792,12 @@ static void network_send_buffer (char *buffer, size_t buffer_len) /* {{{ */ { #if HAVE_LIBGCRYPT if (se->data.client.security_level == SECURITY_LEVEL_ENCRYPT) - networt_send_buffer_encrypted (se, buffer, buffer_len); + network_send_buffer_encrypted (se, buffer, buffer_len); else if (se->data.client.security_level == SECURITY_LEVEL_SIGN) - networt_send_buffer_signed (se, buffer, buffer_len); + network_send_buffer_signed (se, buffer, buffer_len); else /* if (se->data.client.security_level == SECURITY_LEVEL_NONE) */ #endif /* HAVE_LIBGCRYPT */ - networt_send_buffer_plain (se, buffer, buffer_len); + network_send_buffer_plain (se, buffer, buffer_len); } /* for (sending_sockets) */ } /* }}} void network_send_buffer */ @@ -3192,7 +3190,7 @@ static int network_config_add_server (const oconfig_item_t *ci) /* {{{ */ } /* No call to sockent_client_connect() here -- it is called from - * networt_send_buffer_plain(). */ + * network_send_buffer_plain(). */ status = sockent_add (se); if (status != 0)