]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #2426 from pacovn/Coverity_23089_Buffer_not_null_terminated
authorRafael Zalamena <rzalamena@users.noreply.github.com>
Thu, 14 Jun 2018 21:02:34 +0000 (18:02 -0300)
committerGitHub <noreply@github.com>
Thu, 14 Jun 2018 21:02:34 +0000 (18:02 -0300)
ospfd: buffer termination (Coverity 23089)

ospfd/ospf_vty.c
ospfd/ospf_vty.h

index 79f57826cbbf20b5225972f94620494db59d54a6..31cffea7f2350be03bd6233a409073da3d3bb380 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));
 }
@@ -9764,10 +9762,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);
@@ -9842,12 +9837,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(
@@ -9872,7 +9865,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) {
@@ -10007,8 +10000,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 */