lib: more zclient fixes; str termination, vrfs...

* 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>
This commit is contained in:
Quentin Young 2020-03-02 18:47:11 -05:00
parent 229d0d4edc
commit f17a9d0a07

View File

@ -1714,15 +1714,23 @@ stream_failure:
static int zclient_vrf_add(struct zclient *zclient, vrf_id_t vrf_id) static int zclient_vrf_add(struct zclient *zclient, vrf_id_t vrf_id)
{ {
struct vrf *vrf; struct vrf *vrf;
char vrfname_tmp[VRF_NAMSIZ]; char vrfname_tmp[VRF_NAMSIZ + 1] = {};
struct vrf_data data; struct vrf_data data;
STREAM_GET(&data, zclient->ibuf, sizeof(struct vrf_data)); STREAM_GET(&data, zclient->ibuf, sizeof(struct vrf_data));
/* Read interface name. */ /* Read interface name. */
STREAM_GET(vrfname_tmp, zclient->ibuf, VRF_NAMSIZ); STREAM_GET(vrfname_tmp, zclient->ibuf, VRF_NAMSIZ);
if (strlen(vrfname_tmp) == 0)
goto stream_failure;
/* Lookup/create vrf by vrf_id. */ /* Lookup/create vrf by vrf_id. */
vrf = vrf_get(vrf_id, vrfname_tmp); 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; vrf->data.l.table_id = data.l.table_id;
memcpy(vrf->data.l.netns_name, data.l.netns_name, NS_NAMSIZ); memcpy(vrf->data.l.netns_name, data.l.netns_name, NS_NAMSIZ);
/* overwrite default vrf */ /* 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 *zebra_interface_state_read(struct stream *s, vrf_id_t vrf_id)
{ {
struct interface *ifp; struct interface *ifp;
char ifname_tmp[INTERFACE_NAMSIZ]; char ifname_tmp[INTERFACE_NAMSIZ + 1] = {};
/* Read interface name. */ /* Read interface name. */
STREAM_GET(ifname_tmp, s, INTERFACE_NAMSIZ); 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. */ /* Read interface's index. */
STREAM_GETL(s, ifp_tmp.ifindex); STREAM_GETL(s, ifp_tmp.ifindex);
if (ifp_tmp.ifindex < 0)
goto stream_failure;
STREAM_GETC(s, ifp_tmp.status); STREAM_GETC(s, ifp_tmp.status);
/* Read interface's value. */ /* 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 vrf_id,
vrf_id_t *new_vrf_id) vrf_id_t *new_vrf_id)
{ {
char ifname[INTERFACE_NAMSIZ]; char ifname[INTERFACE_NAMSIZ + 1] = {};
struct interface *ifp; struct interface *ifp;
vrf_id_t new_id; vrf_id_t new_id;