X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetlink.c;h=806265a28001ae49dddb839bb2ddd955163fb7e4;hb=904a45ef1b06bf7b14238af6d2aeb9bce176daf7;hp=051458f69aceebb9a07d00e7e07f19c239715df4;hpb=5627feac81780856c5d68cca40eb36cf2f25e96c;p=collectd.git diff --git a/src/netlink.c b/src/netlink.c index 051458f6..806265a2 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -27,8 +27,8 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" +#include "utils/common/common.h" #include @@ -92,12 +92,12 @@ struct qos_stats { }; static int ir_ignorelist_invert = 1; -static ir_ignorelist_t *ir_ignorelist_head = NULL; +static ir_ignorelist_t *ir_ignorelist_head; static struct mnl_socket *nl; -static char **iflist = NULL; -static size_t iflist_len = 0; +static char **iflist; +static size_t iflist_len; static const char *config_keys[] = {"Interface", "VerboseInterface", "QDisc", "Class", @@ -198,7 +198,8 @@ static void submit_two(const char *dev, const char *type, const char *type_instance, derive_t rx, derive_t tx) { value_list_t vl = VALUE_LIST_INIT; value_t values[] = { - {.derive = rx}, {.derive = tx}, + {.derive = rx}, + {.derive = tx}, }; vl.values = values; @@ -449,7 +450,7 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) { const char *tc_type; char tc_inst[DATA_MAX_NAME_LEN]; - _Bool stats_submitted = 0; + bool stats_submitted = false; if (nlh->nlmsg_type == RTM_NEWQDISC) tc_type = "qdisc"; @@ -509,8 +510,8 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) { if (strcmp(tc_type, "filter") == 0) numberic_id = tm->tcm_parent; - snprintf(tc_inst, sizeof(tc_inst), "%s-%x:%x", kind, numberic_id >> 16, - numberic_id & 0x0000FFFF); + ssnprintf(tc_inst, sizeof(tc_inst), "%s-%x:%x", kind, numberic_id >> 16, + numberic_id & 0x0000FFFF); } DEBUG("netlink plugin: qos_filter_cb: got %s for %s (%i).", tc_type, dev, @@ -539,9 +540,15 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) { if (q_stats.bs != NULL || q_stats.qs != NULL) { char type_instance[DATA_MAX_NAME_LEN]; - stats_submitted = 1; + stats_submitted = true; - snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst); + int r = ssnprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, + tc_inst); + if ((size_t)r >= sizeof(type_instance)) { + ERROR("netlink plugin: type_instance truncated to %zu bytes, need %d", + sizeof(type_instance), r); + return MNL_CB_ERROR; + } if (q_stats.bs != NULL) { submit_one(dev, "ipt_bytes", type_instance, q_stats.bs->bytes); @@ -574,7 +581,13 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) { if (!stats_submitted && ts != NULL) { char type_instance[DATA_MAX_NAME_LEN]; - snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst); + int r = ssnprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, + tc_inst); + if ((size_t)r >= sizeof(type_instance)) { + ERROR("netlink plugin: type_instance truncated to %zu bytes, need %d", + sizeof(type_instance), r); + return MNL_CB_ERROR; + } submit_one(dev, "ipt_bytes", type_instance, ts->bytes); submit_one(dev, "ipt_packets", type_instance, ts->packets);