diff options
author | paco <paco@voltanet.io> | 2018-06-13 14:43:18 +0200 |
---|---|---|
committer | paco <paco@voltanet.io> | 2018-06-14 17:43:19 +0200 |
commit | 1f9d4e3d498a12882285dcd2a40ed60ca3a862af (patch) | |
tree | 11d05322bc82f53ca94f02035b221b7765dc18fc | |
parent | Merge pull request #2298 from qlyoung/pipe-actions-vtysh (diff) | |
download | frr-1f9d4e3d498a12882285dcd2a40ed60ca3a862af.tar.xz frr-1f9d4e3d498a12882285dcd2a40ed60ca3a862af.zip |
ospfd: buffer termination (Coverity 23089)
Details:
- INET_ADDRSTRLEN is 16, for xxx.xxx.xxx\0, so 15 is now passed
to the strncpy call instead of 16, ensuring ASCII-z output
Signed-off-by: F. Aragon <paco@voltanet.io>
-rw-r--r-- | ospfd/ospf_vty.c | 23 | ||||
-rw-r--r-- | ospfd/ospf_vty.h | 1 |
2 files changed, 7 insertions, 17 deletions
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 21567c6ce..ef83e5f17 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -72,13 +72,11 @@ int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt) return 0; } -void area_id2str(char *buf, int length, struct in_addr *area_id, - int area_id_fmt) +static void area_id2str(char *buf, int length, struct in_addr *area_id, + int area_id_fmt) { - memset(buf, 0, length); - if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) - strncpy(buf, inet_ntoa(*area_id), length); + inet_ntop(AF_INET, area_id, buf, length); else sprintf(buf, "%lu", (unsigned long)ntohl(area_id->s_addr)); } @@ -9788,10 +9786,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf) else vty_out(vty, " ip ospf"); - - size_t buflen = MAX(strlen("4294967295"), - strlen("255.255.255.255")); - char buf[buflen]; + char buf[INET_ADDRSTRLEN]; area_id2str(buf, sizeof(buf), ¶ms->if_area, params->if_area_id_fmt); @@ -9866,12 +9861,10 @@ static int config_write_network_area(struct vty *vty, struct ospf *ospf) if (rn->info) { struct ospf_network *n = rn->info; - memset(buf, 0, INET_ADDRSTRLEN); - /* Create Area ID string by specified Area ID format. */ if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) - strncpy((char *)buf, inet_ntoa(n->area_id), - INET_ADDRSTRLEN); + inet_ntop(AF_INET, &n->area_id, (char *)buf, + sizeof(buf)); else sprintf((char *)buf, "%lu", (unsigned long int)ntohl( @@ -9896,7 +9889,7 @@ static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { struct route_node *rn1; - area_id2str((char *)buf, INET_ADDRSTRLEN, &area->area_id, + area_id2str((char *)buf, sizeof(buf), &area->area_id, area->area_id_fmt); if (area->auth_type != OSPF_AUTH_NULL) { @@ -10031,8 +10024,6 @@ static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) struct ospf_interface *oi; if (vl_data != NULL) { - memset(buf, 0, INET_ADDRSTRLEN); - area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, vl_data->vl_area_id_fmt); oi = vl_data->vl_oi; diff --git a/ospfd/ospf_vty.h b/ospfd/ospf_vty.h index 559109972..79aabe7b4 100644 --- a/ospfd/ospf_vty.h +++ b/ospfd/ospf_vty.h @@ -53,6 +53,5 @@ extern void ospf_vty_init(void); extern void ospf_vty_show_init(void); extern void ospf_vty_clear_init(void); extern int str2area_id(const char *, struct in_addr *, int *); -extern void area_id2str(char *, int, struct in_addr *, int); #endif /* _QUAGGA_OSPF_VTY_H */ |