Skip to content

Commit 886bfb5

Browse files
committed
Use strscpy instead of strncpy.
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]>
1 parent 4752bb9 commit 886bfb5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/linux/kernel_tunnel.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static int os_ip_tunnel(const char *name, void *target) {
150150
if (target) {
151151
p4.iph.daddr = *((in_addr_t *) target);
152152
}
153-
strncpy(p4.name, name, IFNAMSIZ);
153+
strscpy(p4.name, name, IFNAMSIZ);
154154
} else {
155155
#ifdef LINUX_IPV6_TUNNEL
156156
p = (void *) &p6;
@@ -160,13 +160,13 @@ static int os_ip_tunnel(const char *name, void *target) {
160160
if (target) {
161161
p6.raddr = *((struct in6_addr *) target);
162162
}
163-
strncpy(p6.name, name, IFNAMSIZ);
163+
strscpy(p6.name, name, IFNAMSIZ);
164164
#else /* LINUX_IPV6_TUNNEL */
165165
return 0;
166166
#endif /* LINUX_IPV6_TUNNEL */
167167
}
168168

169-
strncpy(ifr.ifr_name, name, IFNAMSIZ);
169+
strscpy(ifr.ifr_name, name, IFNAMSIZ);
170170
ifr.ifr_ifru.ifru_data = p;
171171

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

237-
strncpy(t->if_name, name, IFNAMSIZ);
237+
strscpy(t->if_name, name, IFNAMSIZ);
238238
t->if_index = if_idx;
239239

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

0 commit comments

Comments
 (0)