Skip to content

Commit

Permalink
Use strscpy instead of strncpy.
Browse files Browse the repository at this point in the history
    Coverity:

    CID 739613 (#1 of 1): Buffer not null terminated (BUFFER_SIZE_WARNING)
    At (6): Calling strncpy with a maximum size argument of 16 bytes on destination array "t->if_name" of size 16 bytes might leave the destination string unterminated.

    CID 739614 (#1 of 3): Buffer not null terminated (BUFFER_SIZE_WARNING)
    At (4): Calling strncpy with a maximum size argument of 16 bytes on destination array "p4.name" of size 16 bytes might leave the destination string unterminated.

    CID 739614 (#2 of 3): Buffer not null terminated (BUFFER_SIZE_WARNING)
    At (4): Calling strncpy with a maximum size argument of 16 bytes on destination array "p6.name" of size 16 bytes might leave the destination string unterminated.

    CID 739614 (#3 of 3): Buffer not null terminated (BUFFER_SIZE_WARNING)
    At (5): Calling strncpy with a maximum size argument of 16 bytes on destination array "ifr.ifr_ifrn.ifrn_name" of size 16 bytes might leave the destination string unterminated.

    Signed-off-by: Henning Rogge <[email protected]>
  • Loading branch information
HRogge committed Oct 22, 2012
1 parent 4752bb9 commit 886bfb5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/linux/kernel_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static int os_ip_tunnel(const char *name, void *target) {
if (target) {
p4.iph.daddr = *((in_addr_t *) target);
}
strncpy(p4.name, name, IFNAMSIZ);
strscpy(p4.name, name, IFNAMSIZ);
} else {
#ifdef LINUX_IPV6_TUNNEL
p = (void *) &p6;
Expand All @@ -160,13 +160,13 @@ static int os_ip_tunnel(const char *name, void *target) {
if (target) {
p6.raddr = *((struct in6_addr *) target);
}
strncpy(p6.name, name, IFNAMSIZ);
strscpy(p6.name, name, IFNAMSIZ);
#else /* LINUX_IPV6_TUNNEL */
return 0;
#endif /* LINUX_IPV6_TUNNEL */
}

strncpy(ifr.ifr_name, name, IFNAMSIZ);
strscpy(ifr.ifr_name, name, IFNAMSIZ);
ifr.ifr_ifru.ifru_data = p;

if ((err = ioctl(olsr_cnf->ioctl_s, target != NULL ? SIOCADDTUNNEL : SIOCDELTUNNEL, &ifr))) {
Expand Down Expand Up @@ -234,7 +234,7 @@ struct olsr_iptunnel_entry *olsr_os_add_ipip_tunnel(union olsr_ip_addr *target,
memcpy(&t->target, target, sizeof(*target));
t->node.key = &t->target;

strncpy(t->if_name, name, IFNAMSIZ);
strscpy(t->if_name, name, IFNAMSIZ);
t->if_index = if_idx;

avl_insert(&tunnel_tree, &t->node, AVL_DUP_NO);
Expand Down

0 comments on commit 886bfb5

Please sign in to comment.