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;
Comment on lines +293 to 294

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject malformed string parts instead of keeping stale type

When a packet already set hdr.type, an empty or unterminated PART_TYPE now just skips this assignment and leaves the previous type in place, so the following PART_VALUE can be encoded under stale metadata instead of rejecting the malformed identifier. This is reachable with a multi-value collectd datagram where a later type part has part_len == 4 or lacks the trailing NUL; returning an error here (and for the other string identifiers) avoids silently corrupting the emitted metric labels.

Useful? React with 👍 / 👎.

}
break;
case PART_TYPE_INSTANCE:
if (ptr[size] == '\0') {
if (size > 0 && ptr[size - 1] == '\0') {
hdr.type_instance = ptr;
}
break;
Expand Down
Loading