From: Thomas Haller Date: Mon, 23 Oct 2017 09:35:32 +0000 (+0200) Subject: route/vlan: fix cloning vlan link in vlan_clone() X-Git-Tag: libnl3_5_0~59^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9d68741065182f4c75a17426246f12a4aeb3c56;p=libnl route/vlan: fix cloning vlan link in vlan_clone() We need to copy the entire source struct over from source to destination. The only thing that needs special handling is to deep-clone the vi_egress_qos buffer. Fixes: a7469ce758fac3631df6ce72eb3f89150070e7f8 --- diff --git a/lib/route/link/vlan.c b/lib/route/link/vlan.c index 477c9af..23fdf66 100644 --- a/lib/route/link/vlan.c +++ b/lib/route/link/vlan.c @@ -264,19 +264,28 @@ static int vlan_clone(struct rtnl_link *dst, struct rtnl_link *src) { struct vlan_info *vdst, *vsrc = src->l_info; int err; + struct vlan_map *p = NULL; dst->l_info = NULL; if ((err = rtnl_link_set_type(dst, "vlan")) < 0) return err; vdst = dst->l_info; - vdst->vi_egress_qos = calloc(vsrc->vi_egress_size, - sizeof(struct vlan_map)); - if (!vdst->vi_egress_qos) - return -NLE_NOMEM; + if (vsrc->vi_negress) { + p = calloc(vsrc->vi_negress, + sizeof(struct vlan_map)); + if (!p) + return -NLE_NOMEM; + } - memcpy(vdst->vi_egress_qos, vsrc->vi_egress_qos, - vsrc->vi_egress_size * sizeof(struct vlan_map)); + *vdst = *vsrc; + + if (vsrc->vi_negress) { + vdst->vi_egress_size = vsrc->vi_negress; + vdst->vi_egress_qos = p; + memcpy(vdst->vi_egress_qos, vsrc->vi_egress_qos, + vsrc->vi_negress * sizeof(struct vlan_map)); + } return 0; }