From a3dd3831138a4167ceb8782a63ef123832e8bfba Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Tue, 15 May 2018 21:05:27 +0200 Subject: [PATCH] netlink plugin: fix truncation warnings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit CC src/netlink_la-netlink.lo src/netlink.c: In function ‘qos_filter_cb’: src/netlink.c:544:58: warning: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size between 121 and 122 [-Wformat-truncation=] snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst); ^~ ~~~~~~~ src/netlink.c:544:7: note: ‘snprintf’ output between 7 and 135 bytes into a destination of size 128 snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/netlink.c:577:58: warning: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size between 121 and 122 [-Wformat-truncation=] snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst); ^~ ~~~~~~~ src/netlink.c:577:7: note: ‘snprintf’ output between 7 and 135 bytes into a destination of size 128 snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CCLD netlink.la --- src/netlink.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/netlink.c b/src/netlink.c index 04585479..0bd598cb 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -541,7 +541,13 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) { stats_submitted = true; - snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst); + int r = snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, + tc_inst); + if (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 +580,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 = snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, + tc_inst); + if (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); -- 2.11.0