diff --git a/plugins/in_collectd/netprot.c b/plugins/in_collectd/netprot.c index a7f13e92d1f..dd2d11104a9 100644 --- a/plugins/in_collectd/netprot.c +++ b/plugins/in_collectd/netprot.c @@ -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; } @@ -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; @@ -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;