Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions plugins/in_collectd/netprot.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ int netprot_to_msgpack(char *buf, int len, struct mk_list *tdb,
part_type = be16read(buf);
part_len = be16read((unsigned char *) buf + 2);

if (len < part_len) {
flb_error("[in_collectd] data truncated (%i < %i)", len, part_len);
if (part_len < 4 || len < part_len) {
flb_error("[in_collectd] invalid part length (%i, remaining %i)",
part_len, len);
return -1;
}

Expand All @@ -268,7 +269,7 @@ int netprot_to_msgpack(char *buf, int len, struct mk_list *tdb,

switch (part_type) {
case PART_HOST:
if (ptr[size] == '\0') {
if (size > 0 && ptr[size - 1] == '\0') {
hdr.host = ptr;
}
break;
Expand All @@ -279,22 +280,22 @@ int netprot_to_msgpack(char *buf, int len, struct mk_list *tdb,
hdr.time = hr2time(be64read(ptr));
break;
case PART_PLUGIN:
if (ptr[size] == '\0') {
if (size > 0 && ptr[size - 1] == '\0') {
hdr.plugin = ptr;
}
break;
case PART_PLUGIN_INSTANCE:
if (ptr[size] == '\0') {
if (size > 0 && ptr[size - 1] == '\0') {
hdr.plugin_instance = ptr;
}
break;
case PART_TYPE:
if (ptr[size] == '\0') {
if (size > 0 && ptr[size - 1] == '\0') {
hdr.type = ptr;
}
break;
case PART_TYPE_INSTANCE:
if (ptr[size] == '\0') {
if (size > 0 && ptr[size - 1] == '\0') {
hdr.type_instance = ptr;
}
break;
Expand Down
Loading