From b9885692cb283a674e04528486984fb61f92a190 Mon Sep 17 00:00:00 2001 From: Chris Leech Date: Tue, 23 Mar 2021 11:21:17 -0700 Subject: [PATCH 3/5] fix VLAN device name overflow check check snprintf return for truncation Signed-off-by: Chris Leech --- fipvlan.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fipvlan.c b/fipvlan.c index fe8d7955cc5..3ce913d5eaf 100644 --- a/fipvlan.c +++ b/fipvlan.c @@ -624,8 +624,16 @@ create_and_start_vlan(struct fcf *fcf, bool vn2vn) real_dev->ifname, fcf->vlan, vlan->ifname); rc = 0; } else { - snprintf(vlan_name, IFNAMSIZ, "%s.%d%s", - real_dev->ifname, fcf->vlan, config.suffix); + rc = snprintf(vlan_name, IFNAMSIZ, "%s.%d%s", + real_dev->ifname, fcf->vlan, + config.suffix); + if (rc < 0 || rc >= IFNAMSIZ) { + printf("Failed to create VLAN device " + "(name %s.%d%s is too long)\n", + real_dev->ifname, fcf->vlan, + config.suffix); + return -EINVAL; + } rc = vlan_create(fcf->ifindex, fcf->vlan, vlan_name); if (rc < 0) printf("Failed to create VLAN device %s\n\t%s\n", -- 2.26.2