projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7c643fa
)
network plugin: Improve "Buffer too small" error message.
author
Florian Forster
<octo@collectd.org>
Fri, 5 Sep 2014 13:54:48 +0000
(15:54 +0200)
committer
Florian Forster
<octo@collectd.org>
Fri, 5 Sep 2014 13:54:51 +0000
(15:54 +0200)
References: #724
src/network.c
patch
|
blob
|
history
diff --git
a/src/network.c
b/src/network.c
index
b191983
..
979d57d
100644
(file)
--- a/
src/network.c
+++ b/
src/network.c
@@
-917,15
+917,19
@@
static int parse_part_number (void **ret_buffer, size_t *ret_buffer_len,
} /* int parse_part_number */
static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len,
} /* int parse_part_number */
static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len,
- char *output,
in
t output_len)
+ char *output,
size_t cons
t output_len)
{
char *buffer = *ret_buffer;
size_t buffer_len = *ret_buffer_len;
uint16_t tmp16;
{
char *buffer = *ret_buffer;
size_t buffer_len = *ret_buffer_len;
uint16_t tmp16;
- size_t header_size = 2 * sizeof (uint16_t);
+ size_t
const
header_size = 2 * sizeof (uint16_t);
uint16_t pkg_length;
uint16_t pkg_length;
+ size_t payload_size;
+
+ if (output_len <= 0)
+ return (EINVAL);
if (buffer_len < header_size)
{
if (buffer_len < header_size)
{
@@
-944,6
+948,7
@@
static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len,
memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
buffer += sizeof (tmp16);
pkg_length = ntohs (tmp16);
memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
buffer += sizeof (tmp16);
pkg_length = ntohs (tmp16);
+ payload_size = ((size_t) pkg_length) - header_size;
/* Check that packet fits in the input buffer */
if (pkg_length > buffer_len)
/* Check that packet fits in the input buffer */
if (pkg_length > buffer_len)
@@
-969,22
+974,24
@@
static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len,
/* Check that the package data fits into the output buffer.
* The previous if-statement ensures that:
* `pkg_length > header_size' */
/* Check that the package data fits into the output buffer.
* The previous if-statement ensures that:
* `pkg_length > header_size' */
- if ((output_len < 0)
- || ((size_t) output_len < ((size_t) pkg_length - header_size)))
+ if (output_len < payload_size)
{
WARNING ("network plugin: parse_part_string: "
{
WARNING ("network plugin: parse_part_string: "
- "Output buffer too small.");
+ "Buffer too small: "
+ "Output buffer holds %zu bytes, "
+ "which is too small to hold the received "
+ "%zu byte string.",
+ output_len, payload_size);
return (-1);
}
/* All sanity checks successfull, let's copy the data over */
return (-1);
}
/* All sanity checks successfull, let's copy the data over */
- output_len = pkg_length - header_size;
- memcpy ((void *) output, (void *) buffer, output_len);
- buffer += output_len;
+ memcpy ((void *) output, (void *) buffer, payload_size);
+ buffer += payload_size;
/* For some very weird reason '\0' doesn't do the trick on SPARC in
* this statement. */
/* For some very weird reason '\0' doesn't do the trick on SPARC in
* this statement. */
- if (output[
output_len
- 1] != 0)
+ if (output[
payload_size
- 1] != 0)
{
WARNING ("network plugin: parse_part_string: "
"Received string does not end "
{
WARNING ("network plugin: parse_part_string: "
"Received string does not end "