]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfd: buffer termination (Coverity 23089)
authorpaco <paco@voltanet.io>
Wed, 13 Jun 2018 12:43:18 +0000 (14:43 +0200)
committerpaco <paco@voltanet.io>
Thu, 14 Jun 2018 15:43:19 +0000 (17:43 +0200)
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>
ospfd/ospf_vty.c
ospfd/ospf_vty.h

index 21567c6ce6cd21384f1da4cd344db4501c82a624..ef83e5f175218991b907f1f75da79d9175ca4c17 100644 (file)
@@ -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), &params->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;
index 559109972cc58f83af4b9f0060ff964161fc64a6..79aabe7b4ea4397b718b9e6240dbcba276ce779f 100644 (file)
@@ -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 */