]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: more zclient fixes; str termination, vrfs...
authorQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 2 Mar 2020 23:47:11 +0000 (18:47 -0500)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 13 Apr 2020 17:25:25 +0000 (13:25 -0400)
* Don't crash if we get a request to create an existing VRF
* Ensure interface & vrf names are null terminated...again

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/zclient.c

index e5336d8ec262885eef1432501a67e4c43c8f5ed4..fd822ba0832bc59636688c860ed9248dbb63597a 100644 (file)
@@ -1714,15 +1714,23 @@ stream_failure:
 static int zclient_vrf_add(struct zclient *zclient, vrf_id_t vrf_id)
 {
        struct vrf *vrf;
-       char vrfname_tmp[VRF_NAMSIZ];
+       char vrfname_tmp[VRF_NAMSIZ + 1] = {};
        struct vrf_data data;
 
        STREAM_GET(&data, zclient->ibuf, sizeof(struct vrf_data));
        /* Read interface name. */
        STREAM_GET(vrfname_tmp, zclient->ibuf, VRF_NAMSIZ);
 
+       if (strlen(vrfname_tmp) == 0)
+               goto stream_failure;
+
        /* Lookup/create vrf by vrf_id. */
        vrf = vrf_get(vrf_id, vrfname_tmp);
+
+       /* Maybe it already exists? */
+       if (!vrf && vrf_get(vrf_id, NULL) != NULL)
+               return 0;
+
        vrf->data.l.table_id = data.l.table_id;
        memcpy(vrf->data.l.netns_name, data.l.netns_name, NS_NAMSIZ);
        /* overwrite default vrf */
@@ -1790,7 +1798,7 @@ stream_failure:
 struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t vrf_id)
 {
        struct interface *ifp;
-       char ifname_tmp[INTERFACE_NAMSIZ];
+       char ifname_tmp[INTERFACE_NAMSIZ + 1] = {};
 
        /* Read interface name. */
        STREAM_GET(ifname_tmp, s, INTERFACE_NAMSIZ);
@@ -1975,6 +1983,10 @@ static int zebra_interface_if_set_value(struct stream *s, struct interface *ifp)
 
        /* Read interface's index. */
        STREAM_GETL(s, ifp_tmp.ifindex);
+
+       if (ifp_tmp.ifindex < 0)
+               goto stream_failure;
+
        STREAM_GETC(s, ifp_tmp.status);
 
        /* Read interface's value. */
@@ -2304,7 +2316,7 @@ struct interface *zebra_interface_vrf_update_read(struct stream *s,
                                                  vrf_id_t vrf_id,
                                                  vrf_id_t *new_vrf_id)
 {
-       char ifname[INTERFACE_NAMSIZ];
+       char ifname[INTERFACE_NAMSIZ + 1] = {};
        struct interface *ifp;
        vrf_id_t new_id;