summaryrefslogtreecommitdiffstats
path: root/zebra
diff options
context:
space:
mode:
authorRuss White <russ@riw.us>2019-02-26 17:08:18 +0100
committerGitHub <noreply@github.com>2019-02-26 17:08:18 +0100
commit24ee026b1ad29ad0240d9acb162198b74406c7d0 (patch)
treea6e46eb431b6631a9f92ff5ba084a71707503844 /zebra
parentMerge pull request #3866 from donaldsharp/ospf_allow_vrf_starup (diff)
parentzebra: remove all instances of strncpy (diff)
downloadfrr-24ee026b1ad29ad0240d9acb162198b74406c7d0.tar.xz
frr-24ee026b1ad29ad0240d9acb162198b74406c7d0.zip
Merge pull request #3865 from qlyoung/fix-zebra-vxlan-smelly-strings
zebra: replace strncpy with strlcpy
Diffstat (limited to 'zebra')
-rw-r--r--zebra/if_ioctl.c2
-rw-r--r--zebra/if_ioctl_solaris.c3
-rw-r--r--zebra/ioctl.c10
-rw-r--r--zebra/ioctl_solaris.c6
-rw-r--r--zebra/zebra_vxlan.c12
5 files changed, 16 insertions, 17 deletions
diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c
index debc151d7..8bec25635 100644
--- a/zebra/if_ioctl.c
+++ b/zebra/if_ioctl.c
@@ -147,7 +147,7 @@ static int if_get_hwaddr(struct interface *ifp)
struct ifreq ifreq;
int i;
- strncpy(ifreq.ifr_name, ifp->name, IFNAMSIZ);
+ strlcpy(ifreq.ifr_name, ifp->name, sizeof(ifreq.ifr_name));
ifreq.ifr_addr.sa_family = AF_INET;
/* Fetch Hardware address if available. */
diff --git a/zebra/if_ioctl_solaris.c b/zebra/if_ioctl_solaris.c
index 2c29930c3..8b539a904 100644
--- a/zebra/if_ioctl_solaris.c
+++ b/zebra/if_ioctl_solaris.c
@@ -247,7 +247,8 @@ static int if_get_addr(struct interface *ifp, struct sockaddr *addr,
* We need to use the logical interface name / label, if we've been
* given one, in order to get the right address
*/
- strncpy(lifreq.lifr_name, (label ? label : ifp->name), IFNAMSIZ);
+ strlcpy(lifreq.lifr_name, (label ? label : ifp->name),
+ sizeof(lifreq.lifr_name));
/* Interface's address. */
memcpy(&lifreq.lifr_addr, addr, ADDRLEN(addr));
diff --git a/zebra/ioctl.c b/zebra/ioctl.c
index ebe1edcae..9499c731e 100644
--- a/zebra/ioctl.c
+++ b/zebra/ioctl.c
@@ -213,7 +213,7 @@ int if_set_prefix(struct interface *ifp, struct connected *ifc)
rib_lookup_and_pushup(p, ifp->vrf_id);
memset(&addreq, 0, sizeof addreq);
- strncpy((char *)&addreq.ifra_name, ifp->name, sizeof addreq.ifra_name);
+ strlcpy(addreq.ifra_name, ifp->name, sizeof(addreq.ifra_name));
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_addr = p->prefix;
@@ -267,7 +267,7 @@ int if_unset_prefix(struct interface *ifp, struct connected *ifc)
p = (struct prefix_ipv4 *)ifc->address;
memset(&addreq, 0, sizeof addreq);
- strncpy((char *)&addreq.ifra_name, ifp->name, sizeof addreq.ifra_name);
+ strlcpy(addreq.ifra_name, ifp->name, sizeof(addreq.ifra_name));
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_addr = p->prefix;
@@ -412,7 +412,7 @@ void if_get_flags(struct interface *ifp)
if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) {
(void)memset(&ifmr, 0, sizeof(ifmr));
- strncpy(ifmr.ifm_name, ifp->name, IFNAMSIZ);
+ strlcpy(ifmr.ifm_name, ifp->name, sizeof(ifmr.ifm_name));
/* Seems not all interfaces implement this ioctl */
if (if_ioctl(SIOCGIFMEDIA, (caddr_t)&ifmr) == -1 &&
@@ -514,7 +514,7 @@ int if_prefix_add_ipv6(struct interface *ifp, struct connected *ifc)
p = (struct prefix_ipv6 *)ifc->address;
memset(&addreq, 0, sizeof addreq);
- strncpy((char *)&addreq.ifra_name, ifp->name, sizeof addreq.ifra_name);
+ strlcpy(addreq.ifra_name, ifp->name, sizeof(addreq.ifra_name));
memset(&addr, 0, sizeof(struct sockaddr_in6));
addr.sin6_addr = p->prefix;
@@ -557,7 +557,7 @@ int if_prefix_delete_ipv6(struct interface *ifp, struct connected *ifc)
p = (struct prefix_ipv6 *)ifc->address;
memset(&addreq, 0, sizeof addreq);
- strncpy((char *)&addreq.ifra_name, ifp->name, sizeof addreq.ifra_name);
+ strlcpy(addreq.ifra_name, ifp->name, sizeof(addreq.ifra_name));
memset(&addr, 0, sizeof(struct sockaddr_in6));
addr.sin6_addr = p->prefix;
diff --git a/zebra/ioctl_solaris.c b/zebra/ioctl_solaris.c
index fc554219b..c523ee983 100644
--- a/zebra/ioctl_solaris.c
+++ b/zebra/ioctl_solaris.c
@@ -44,7 +44,7 @@ extern struct zebra_privs_t zserv_privs;
/* clear and set interface name string */
void lifreq_set_name(struct lifreq *lifreq, const char *ifname)
{
- strncpy(lifreq->lifr_name, ifname, IFNAMSIZ);
+ strlcpy(lifreq->lifr_name, ifname, sizeof(lifreq->lifr_name));
}
int vrf_if_ioctl(unsigned long request, caddr_t buffer, vrf_id_t vrf_id)
@@ -199,7 +199,7 @@ int if_set_prefix(struct interface *ifp, struct connected *ifc)
ifaddr = *p;
- strncpy(ifreq.ifr_name, ifp->name, IFNAMSIZ);
+ strlcpy(ifreq.ifr_name, ifp->name, sizeof(ifreq.ifr_name));
addr.sin_addr = p->prefix;
addr.sin_family = p->family;
@@ -250,7 +250,7 @@ int if_unset_prefix(struct interface *ifp, struct connected *ifc)
p = (struct prefix_ipv4 *)ifc->address;
- strncpy(ifreq.ifr_name, ifp->name, IFNAMSIZ);
+ strlcpy(ifreq.ifr_name, ifp->name, sizeof(ifreq.ifr_name));
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_family = p->family;
diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c
index 464b1f171..7d4d5db6b 100644
--- a/zebra/zebra_vxlan.c
+++ b/zebra/zebra_vxlan.c
@@ -767,8 +767,7 @@ static void zvni_print_neigh(zebra_neigh_t *n, void *ctxt, json_object *json)
n->detect_start_time.tv_sec);
char tmp_buf[30];
- memset(tmp_buf, 0, 30);
- strncpy(tmp_buf, buf, strlen(buf) - 1);
+ strlcpy(tmp_buf, buf, sizeof(tmp_buf));
vty_out(vty,
" Duplicate detection started at %s, detection count %u\n",
tmp_buf, n->dad_count);
@@ -1148,7 +1147,7 @@ static void zvni_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json)
struct vty *vty;
zebra_neigh_t *n = NULL;
struct listnode *node = NULL;
- char buf1[20];
+ char buf1[ETHER_ADDR_STRLEN];
char buf2[INET6_ADDRSTRLEN];
struct zebra_vrf *zvrf;
struct timeval detect_start_time = {0, 0};
@@ -1289,8 +1288,7 @@ static void zvni_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json)
mac->detect_start_time.tv_sec);
char tmp_buf[30];
- memset(tmp_buf, 0, 30);
- strncpy(tmp_buf, buf, strlen(buf) - 1);
+ strlcpy(tmp_buf, buf, sizeof(tmp_buf));
vty_out(vty,
" Duplicate detection started at %s, detection count %u\n",
tmp_buf, mac->dad_count);
@@ -1323,7 +1321,7 @@ static void zvni_print_mac_hash(struct hash_bucket *bucket, void *ctxt)
struct vty *vty;
json_object *json_mac_hdr = NULL, *json_mac = NULL;
zebra_mac_t *mac;
- char buf1[20];
+ char buf1[ETHER_ADDR_STRLEN];
struct mac_walk_ctx *wctx = ctxt;
vty = wctx->vty;
@@ -1445,7 +1443,7 @@ static void zvni_print_mac_hash_detail(struct hash_bucket *bucket, void *ctxt)
json_object *json_mac_hdr = NULL;
zebra_mac_t *mac;
struct mac_walk_ctx *wctx = ctxt;
- char buf1[20];
+ char buf1[ETHER_ADDR_STRLEN];
vty = wctx->vty;
json_mac_hdr = wctx->json;