projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #1806 from rubenk/network-plugin-size_t
[collectd.git]
/
src
/
network.c
diff --git
a/src/network.c
b/src/network.c
index
171904d
..
4393d08
100644
(file)
--- a/
src/network.c
+++ b/
src/network.c
@@
-30,15
+30,11
@@
#include "common.h"
#include "configfile.h"
#include "utils_fbhash.h"
#include "common.h"
#include "configfile.h"
#include "utils_fbhash.h"
-#include "utils_avltree.h"
#include "utils_cache.h"
#include "utils_complain.h"
#include "network.h"
#include "utils_cache.h"
#include "utils_complain.h"
#include "network.h"
-#if HAVE_PTHREAD_H
-# include <pthread.h>
-#endif
#if HAVE_NETDB_H
# include <netdb.h>
#endif
#if HAVE_NETDB_H
# include <netdb.h>
#endif
@@
-56,7
+52,6
@@
#endif
#if HAVE_LIBGCRYPT
#endif
#if HAVE_LIBGCRYPT
-# include <pthread.h>
# if defined __APPLE__
/* default xcode compiler throws warnings even when deprecated functionality
* is not used. -Werror breaks the build because of erroneous warnings.
# if defined __APPLE__
/* default xcode compiler throws warnings even when deprecated functionality
* is not used. -Werror breaks the build because of erroneous warnings.
@@
-414,10
+409,10
@@
static int network_dispatch_values (value_list_t *vl, /* {{{ */
{
int status;
{
int status;
- if ((vl->time
<
= 0)
- || (strlen (vl->host)
<
= 0)
- || (strlen (vl->plugin)
<
= 0)
- || (strlen (vl->type)
<
= 0))
+ if ((vl->time
=
= 0)
+ || (strlen (vl->host)
=
= 0)
+ || (strlen (vl->plugin)
=
= 0)
+ || (strlen (vl->type)
=
= 0))
return (-EINVAL);
if (!check_receive_okay (vl))
return (-EINVAL);
if (!check_receive_okay (vl))
@@
-498,6
+493,8
@@
static int network_dispatch_notification (notification_t *n) /* {{{ */
#if HAVE_LIBGCRYPT
static void network_init_gcrypt (void) /* {{{ */
{
#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 */
/* 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 */
@@
-512,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
*
* 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
# endif
+
gcry_check_version (NULL);
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 */
gcry_control (GCRYCTL_INITIALIZATION_FINISHED);
} /* }}} void network_init_gcrypt */
@@
-595,11
+605,11
@@
static gcry_cipher_hd_t network_get_aes256_cypher (sockent_t *se, /* {{{ */
} /* }}} int network_get_aes256_cypher */
#endif /* HAVE_LIBGCRYPT */
} /* }}} int network_get_aes256_cypher */
#endif /* HAVE_LIBGCRYPT */
-static int write_part_values (char **ret_buffer,
in
t *ret_buffer_len,
+static int write_part_values (char **ret_buffer,
size_
t *ret_buffer_len,
const data_set_t *ds, const value_list_t *vl)
{
char *packet_ptr;
const data_set_t *ds, const value_list_t *vl)
{
char *packet_ptr;
-
in
t packet_len;
+
size_
t packet_len;
int num_values;
part_header_t pkg_ph;
int num_values;
part_header_t pkg_ph;
@@
-607,7
+617,7
@@
static int write_part_values (char **ret_buffer, int *ret_buffer_len,
uint8_t *pkg_values_types;
value_t *pkg_values;
uint8_t *pkg_values_types;
value_t *pkg_values;
-
in
t offset;
+
size_
t offset;
int i;
num_values = vl->values_len;
int i;
num_values = vl->values_len;
@@
-696,16
+706,16
@@
static int write_part_values (char **ret_buffer, int *ret_buffer_len,
return (0);
} /* int write_part_values */
return (0);
} /* int write_part_values */
-static int write_part_number (char **ret_buffer,
in
t *ret_buffer_len,
+static int write_part_number (char **ret_buffer,
size_
t *ret_buffer_len,
int type, uint64_t value)
{
char *packet_ptr;
int type, uint64_t value)
{
char *packet_ptr;
-
in
t packet_len;
+
size_
t packet_len;
part_header_t pkg_head;
uint64_t pkg_value;
part_header_t pkg_head;
uint64_t pkg_value;
-
in
t offset;
+
size_
t offset;
packet_len = sizeof (pkg_head) + sizeof (pkg_value);
packet_len = sizeof (pkg_head) + sizeof (pkg_value);
@@
-731,16
+741,16
@@
static int write_part_number (char **ret_buffer, int *ret_buffer_len,
return (0);
} /* int write_part_number */
return (0);
} /* int write_part_number */
-static int write_part_string (char **ret_buffer,
in
t *ret_buffer_len,
- int type, const char *str,
in
t str_len)
+static int write_part_string (char **ret_buffer,
size_
t *ret_buffer_len,
+ int type, const char *str,
size_
t str_len)
{
char *buffer;
{
char *buffer;
-
in
t buffer_len;
+
size_
t buffer_len;
uint16_t pkg_type;
uint16_t pkg_length;
uint16_t pkg_type;
uint16_t pkg_length;
-
in
t offset;
+
size_
t offset;
buffer_len = 2 * sizeof (uint16_t) + str_len + 1;
if (*ret_buffer_len < buffer_len)
buffer_len = 2 * sizeof (uint16_t) + str_len + 1;
if (*ret_buffer_len < buffer_len)
@@
-934,7
+944,7
@@
static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len,
uint16_t pkg_length;
size_t payload_size;
uint16_t pkg_length;
size_t payload_size;
- if (output_len
<
= 0)
+ if (output_len
=
= 0)
return (EINVAL);
if (buffer_len < header_size)
return (EINVAL);
if (buffer_len < header_size)
@@
-1250,7
+1260,7
@@
static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */
BUFFER_READ (&username_len, sizeof (username_len));
username_len = ntohs (username_len);
BUFFER_READ (&username_len, sizeof (username_len));
username_len = ntohs (username_len);
- if ((username_len
<
= 0)
+ if ((username_len
=
= 0)
|| (username_len > (part_size - (PART_ENCRYPTION_AES256_SIZE + 1))))
{
NOTICE ("network plugin: parse_part_encr_aes256: "
|| (username_len > (part_size - (PART_ENCRYPTION_AES256_SIZE + 1))))
{
NOTICE ("network plugin: parse_part_encr_aes256: "
@@
-1369,7
+1379,7
@@
static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */
warning_has_been_printed = 1;
}
warning_has_been_printed = 1;
}
- *ret_buffer
+= ph_length
;
+ *ret_buffer
= (void *) (((char *) *ret_buffer) + ph_length)
;
*ret_buffer_size -= ph_length;
return (0);
*ret_buffer_size -= ph_length;
return (0);
@@
-1408,7
+1418,7
@@
static int parse_packet (sockent_t *se, /* {{{ */
(void *) buffer,
sizeof (pkg_type));
memcpy ((void *) &pkg_length,
(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);
sizeof (pkg_length));
pkg_length = ntohs (pkg_length);
@@
-1443,6
+1453,7
@@
static int parse_packet (sockent_t *se, /* {{{ */
printed_ignore_warning = 1;
}
buffer = ((char *) buffer) + pkg_length;
printed_ignore_warning = 1;
}
buffer = ((char *) buffer) + pkg_length;
+ buffer_size -= (size_t) pkg_length;
continue;
}
#endif /* HAVE_LIBGCRYPT */
continue;
}
#endif /* HAVE_LIBGCRYPT */
@@
-1470,6
+1481,7
@@
static int parse_packet (sockent_t *se, /* {{{ */
printed_ignore_warning = 1;
}
buffer = ((char *) buffer) + pkg_length;
printed_ignore_warning = 1;
}
buffer = ((char *) buffer) + pkg_length;
+ buffer_size -= (size_t) pkg_length;
continue;
}
#endif /* HAVE_LIBGCRYPT */
continue;
}
#endif /* HAVE_LIBGCRYPT */
@@
-1581,13
+1593,13
@@
static int parse_packet (sockent_t *se, /* {{{ */
"unknown severity %i.",
n.severity);
}
"unknown severity %i.",
n.severity);
}
- else if (n.time
<
= 0)
+ else if (n.time
=
= 0)
{
INFO ("network plugin: "
"Ignoring notification with "
"time == 0.");
}
{
INFO ("network plugin: "
"Ignoring notification with "
"time == 0.");
}
- else if (strlen (n.message)
<
= 0)
+ else if (strlen (n.message)
=
= 0)
{
INFO ("network plugin: "
"Ignoring notification with "
{
INFO ("network plugin: "
"Ignoring notification with "
@@
-1611,6
+1623,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;
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)) */
}
} /* while (buffer_size > sizeof (part_header_t)) */
@@
-2311,7
+2324,7
@@
static int sockent_server_listen (sockent_t *se) /* {{{ */
freeaddrinfo (ai_list);
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 */
return (-1);
return (0);
} /* }}} int sockent_server_listen */
@@
-2801,7
+2814,7
@@
static void network_send_buffer (char *buffer, size_t buffer_len) /* {{{ */
} /* for (sending_sockets) */
} /* }}} void network_send_buffer */
} /* for (sending_sockets) */
} /* }}} void network_send_buffer */
-static int add_to_buffer (char *buffer,
in
t buffer_size, /* {{{ */
+static int add_to_buffer (char *buffer,
size_
t buffer_size, /* {{{ */
value_list_t *vl_def,
const data_set_t *ds, const value_list_t *vl)
{
value_list_t *vl_def,
const data_set_t *ds, const value_list_t *vl)
{
@@
-3245,10
+3258,10
@@
static int network_config (oconfig_item_t *ci) /* {{{ */
static int network_notification (const notification_t *n,
user_data_t __attribute__((unused)) *user_data)
{
static int network_notification (const notification_t *n,
user_data_t __attribute__((unused)) *user_data)
{
- char buffer[network_config_packet_size];
- char *buffer_ptr = buffer;
-
int
buffer_free = sizeof (buffer);
- int status;
+ char
buffer[network_config_packet_size];
+ char
*buffer_ptr = buffer;
+
size_t
buffer_free = sizeof (buffer);
+ int
status;
if (!check_send_notify_okay (n))
return (0);
if (!check_send_notify_okay (n))
return (0);