Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverity likes coverity #6269

Merged
merged 2 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ospfd/ospf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ struct msg *msg_read(int fd)
struct msg *msg;
struct apimsghdr hdr;
uint8_t buf[OSPF_API_MAX_MSG_SIZE];
int bodylen;
int rlen;
ssize_t bodylen;
ssize_t rlen;

/* Read message header */
rlen = readn(fd, (uint8_t *)&hdr, sizeof(struct apimsghdr));
Expand All @@ -378,8 +378,13 @@ struct msg *msg_read(int fd)

/* Determine body length. */
bodylen = ntohs(hdr.msglen);
if (bodylen > 0) {
if (bodylen > (ssize_t)sizeof(buf)) {
zlog_warn("%s: Body Length of message greater than what we can read",
__func__);
return NULL;
}

if (bodylen > 0) {
/* Read message body */
rlen = readn(fd, buf, bodylen);
if (rlen < 0) {
Expand Down
52 changes: 22 additions & 30 deletions zebra/zebra_fpm_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,23 +431,18 @@ static int netlink_route_info_encode(netlink_route_info_t *ri, char *in_buf,
}

encap = nhi->encap_info.encap_type;
if (encap > FPM_NH_ENCAP_NONE) {
switch (encap) {
case FPM_NH_ENCAP_NONE:
case FPM_NH_ENCAP_MAX:
break;
case FPM_NH_ENCAP_VXLAN:
addattr_l(&req->n, in_buf_len, RTA_ENCAP_TYPE, &encap,
sizeof(uint16_t));
switch (encap) {
case FPM_NH_ENCAP_NONE:
break;
case FPM_NH_ENCAP_VXLAN:
vxlan = &nhi->encap_info.vxlan_encap;
nest = addattr_nest(&req->n, in_buf_len,
RTA_ENCAP);
addattr32(&req->n, in_buf_len, VXLAN_VNI,
vxlan->vni);
addattr_nest_end(&req->n, nest);
break;
case FPM_NH_ENCAP_MAX:
break;
}
vxlan = &nhi->encap_info.vxlan_encap;
nest = addattr_nest(&req->n, in_buf_len, RTA_ENCAP);
addattr32(&req->n, in_buf_len, VXLAN_VNI, vxlan->vni);
addattr_nest_end(&req->n, nest);
break;
}

goto done;
Expand Down Expand Up @@ -484,25 +479,22 @@ static int netlink_route_info_encode(netlink_route_info_t *ri, char *in_buf,
}

encap = nhi->encap_info.encap_type;
if (encap > FPM_NH_ENCAP_NONE) {
switch (encap) {
case FPM_NH_ENCAP_NONE:
case FPM_NH_ENCAP_MAX:
break;
case FPM_NH_ENCAP_VXLAN:
rta_addattr_l(rta, sizeof(buf), RTA_ENCAP_TYPE,
&encap, sizeof(uint16_t));
rtnh->rtnh_len += sizeof(struct rtattr) +
sizeof(uint16_t);
switch (encap) {
case FPM_NH_ENCAP_NONE:
break;
case FPM_NH_ENCAP_VXLAN:
vxlan = &nhi->encap_info.vxlan_encap;
nest = rta_nest(rta, sizeof(buf), RTA_ENCAP);
rta_addattr_l(rta, sizeof(buf), VXLAN_VNI,
&vxlan->vni, sizeof(uint32_t));
nest_len = rta_nest_end(rta, nest);
rtnh->rtnh_len += nest_len;
break;
case FPM_NH_ENCAP_MAX:
break;
}
vxlan = &nhi->encap_info.vxlan_encap;
nest = rta_nest(rta, sizeof(buf), RTA_ENCAP);
rta_addattr_l(rta, sizeof(buf), VXLAN_VNI, &vxlan->vni,
sizeof(uint32_t));
nest_len = rta_nest_end(rta, nest);
rtnh->rtnh_len += nest_len;
break;
}

rtnh = RTNH_NEXT(rtnh);
Expand Down