From: Jo-Philipp Wich Date: Thu, 17 Nov 2022 08:09:09 +0000 (+0100) Subject: treewide: correctly apply IFNAMSIZ limit X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=2cffe0c44e62b9e063fa30ce07431753494c53c2;p=project%2Fnetifd.git treewide: correctly apply IFNAMSIZ limit The `IFNAMSIZ` macro defines the required buffer size to hold a Linux interface name including the terminating zero byte while netifd currently uses an `IFNAMSIZ + 1` limit for interface name buffers. This causes netifd to use overlong names (16 instead of 15 bytes) in netlink communication with the kernel, leading to netlink failure replies due to policy violations. Fix this issue by applying the correct length, that is `IFNAMSIZ` directly, to the corresponding buffers. Ref: https://github.com/openwrt/openwrt/issues/11259 Signed-off-by: Jo-Philipp Wich --- diff --git a/device.h b/device.h index 37f8c37..6751628 100644 --- a/device.h +++ b/device.h @@ -219,7 +219,7 @@ struct device { struct vlist_tree vlans; struct kvlist vlan_aliases; - char ifname[IFNAMSIZ + 1]; + char ifname[IFNAMSIZ]; int ifindex; struct blob_attr *config; diff --git a/iprule.h b/iprule.h index 6d91d06..488aafc 100644 --- a/iprule.h +++ b/iprule.h @@ -77,8 +77,8 @@ struct iprule { struct interface_user out_iface_user; /* device name */ - char in_dev[IFNAMSIZ + 1]; - char out_dev[IFNAMSIZ + 1]; + char in_dev[IFNAMSIZ]; + char out_dev[IFNAMSIZ]; /* everything below is used as avl tree key */ /* don't change the order */ diff --git a/system-linux.c b/system-linux.c index 0f13a99..9fe869f 100644 --- a/system-linux.c +++ b/system-linux.c @@ -1030,7 +1030,7 @@ int system_bonding_set_port(struct device *dev, struct device *port, bool add, b { const char *port_name = port->ifname; const char op_ch = add ? '+' : '-'; - char buf[IFNAMSIZ + 2]; + char buf[IFNAMSIZ + 1]; snprintf(buf, sizeof(buf), "%c%s", op_ch, port_name); system_if_down(port); diff --git a/vlan.c b/vlan.c index 23b20a9..3d444a9 100644 --- a/vlan.c +++ b/vlan.c @@ -128,7 +128,7 @@ static int vlan_set_device_state(struct device *dev, bool up) static void vlan_dev_cb(struct device_user *dep, enum device_event ev) { - char name[IFNAMSIZ + 1]; + char name[IFNAMSIZ]; struct vlan_device *vldev; vldev = container_of(dep, struct vlan_device, dep); @@ -175,7 +175,7 @@ static struct device *get_vlan_device(struct device *dev, char *id_str, bool cre }; struct vlan_device *vldev; struct device_user *dep; - char name[IFNAMSIZ + 1]; + char name[IFNAMSIZ]; char *err = NULL; int id, *alias_id;