Sun Oct 13 07:46:16 2019 UTC ()
ifr_name is nul terminated.  make it so.


(mrg)
diff -r1.3 -r1.4 src/tests/net/can/h_canutils.c
diff -r1.1 -r1.2 src/tests/net/if_vlan/siocXmulti.c

cvs diff -r1.3 -r1.4 src/tests/net/can/h_canutils.c (expand / switch to unified diff)

--- src/tests/net/can/h_canutils.c 2017/05/28 13:55:07 1.3
+++ src/tests/net/can/h_canutils.c 2019/10/13 07:46:16 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: h_canutils.c,v 1.3 2017/05/28 13:55:07 kre Exp $ */ 1/* $NetBSD: h_canutils.c,v 1.4 2019/10/13 07:46:16 mrg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2017 The NetBSD Foundation, Inc. 4 * Copyright (c) 2017 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Manuel Bouyer 8 * by Manuel Bouyer
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 23 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
26 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
28 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34#ifndef lint 34#ifndef lint
35__RCSID("$NetBSD: h_canutils.c,v 1.3 2017/05/28 13:55:07 kre Exp $"); 35__RCSID("$NetBSD: h_canutils.c,v 1.4 2019/10/13 07:46:16 mrg Exp $");
36#endif /* not lint */ 36#endif /* not lint */
37 37
38#include <sys/types.h> 38#include <sys/types.h>
39#include <sys/resource.h> 39#include <sys/resource.h>
40#include <sys/wait.h> 40#include <sys/wait.h>
41#include <sys/sockio.h> 41#include <sys/sockio.h>
42#include <sys/param.h> 42#include <sys/param.h>
43 43
44#include <atf-c.h> 44#include <atf-c.h>
45#include <assert.h> 45#include <assert.h>
46#include <fcntl.h> 46#include <fcntl.h>
47#include <stdio.h> 47#include <stdio.h>
48#include <stdlib.h> 48#include <stdlib.h>
@@ -60,34 +60,36 @@ __RCSID("$NetBSD: h_canutils.c,v 1.3 201 @@ -60,34 +60,36 @@ __RCSID("$NetBSD: h_canutils.c,v 1.3 201
60 60
61void 61void
62cancfg_rump_createif(const char *ifname) 62cancfg_rump_createif(const char *ifname)
63{ 63{
64 int s, rv; 64 int s, rv;
65 struct ifreq ifr; 65 struct ifreq ifr;
66 66
67 s = -1; 67 s = -1;
68 if ((s = rump_sys_socket(AF_CAN, SOCK_RAW, CAN_RAW)) < 0) { 68 if ((s = rump_sys_socket(AF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
69 atf_tc_fail_errno("if config socket"); 69 atf_tc_fail_errno("if config socket");
70 } 70 }
71 71
72 memset(&ifr, 0, sizeof(ifr)); 72 memset(&ifr, 0, sizeof(ifr));
73 strncpy(ifr.ifr_name, ifname, IFNAMSIZ); 73 strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1);
 74 ifr.ifr_name[IFNAMSIZ - 1] = '\0';
74 75
75 if ((rv = rump_sys_ioctl(s, SIOCIFCREATE, &ifr)) < 0) { 76 if ((rv = rump_sys_ioctl(s, SIOCIFCREATE, &ifr)) < 0) {
76 atf_tc_fail_errno("if config create"); 77 atf_tc_fail_errno("if config create");
77 } 78 }
78 79
79 memset(&ifr, 0, sizeof(ifr)); 80 memset(&ifr, 0, sizeof(ifr));
80 strncpy(ifr.ifr_name, ifname, IFNAMSIZ); 81 strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1);
 82 ifr.ifr_name[IFNAMSIZ - 1] = '\0';
81 83
82 if ((rv = rump_sys_ioctl(s, SIOCGIFFLAGS, &ifr)) < 0) { 84 if ((rv = rump_sys_ioctl(s, SIOCGIFFLAGS, &ifr)) < 0) {
83 atf_tc_fail_errno("if config get flags"); 85 atf_tc_fail_errno("if config get flags");
84 } 86 }
85 87
86 ifr.ifr_flags |= IFF_UP; 88 ifr.ifr_flags |= IFF_UP;
87 if ((rv = rump_sys_ioctl(s, SIOCSIFFLAGS, &ifr)) < 0) { 89 if ((rv = rump_sys_ioctl(s, SIOCSIFFLAGS, &ifr)) < 0) {
88 atf_tc_fail_errno("if config set flags"); 90 atf_tc_fail_errno("if config set flags");
89 } 91 }
90} 92}
91 93
92int 94int
93can_recvfrom(int s, struct can_frame *cf, int *len, struct sockaddr_can *sa) 95can_recvfrom(int s, struct can_frame *cf, int *len, struct sockaddr_can *sa)

cvs diff -r1.1 -r1.2 src/tests/net/if_vlan/siocXmulti.c (expand / switch to unified diff)

--- src/tests/net/if_vlan/siocXmulti.c 2018/06/14 08:22:52 1.1
+++ src/tests/net/if_vlan/siocXmulti.c 2019/10/13 07:46:16 1.2
@@ -46,27 +46,28 @@ main(int argc, char *argv[]) @@ -46,27 +46,28 @@ main(int argc, char *argv[])
46 usage(); 46 usage();
47 47
48 if (strcmp(argv[ARG_OP], "add") == 0) 48 if (strcmp(argv[ARG_OP], "add") == 0)
49 req = SIOCADDMULTI; 49 req = SIOCADDMULTI;
50 else if (strcmp(argv[ARG_OP], "del") == 0) 50 else if (strcmp(argv[ARG_OP], "del") == 0)
51 req = SIOCDELMULTI; 51 req = SIOCDELMULTI;
52 else 52 else
53 usage(); 53 usage();
54 54
55 ifidx = if_nametoindex(argv[ARG_IFNAME]); 55 ifidx = if_nametoindex(argv[ARG_IFNAME]);
56 if (ifidx == 0) 56 if (ifidx == 0)
57 err(1, "if_nametoindex(%s)", argv[ARG_IFNAME]); 57 err(1, "if_nametoindex(%s)", argv[ARG_IFNAME]);
58 58
59 strncpy(ifr.ifr_name, argv[ARG_IFNAME], sizeof(ifr.ifr_name)); 59 strncpy(ifr.ifr_name, argv[ARG_IFNAME], sizeof(ifr.ifr_name) - 1);
 60 ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
60 61
61 sin = (struct sockaddr_in *)&ifr.ifr_addr; 62 sin = (struct sockaddr_in *)&ifr.ifr_addr;
62 sin->sin_family = AF_INET; 63 sin->sin_family = AF_INET;
63 sin->sin_len = sizeof(*sin); 64 sin->sin_len = sizeof(*sin);
64 rv = inet_pton(AF_INET, argv[ARG_ADDR], &sin->sin_addr); 65 rv = inet_pton(AF_INET, argv[ARG_ADDR], &sin->sin_addr);
65 66
66 if (rv != 1) { 67 if (rv != 1) {
67 sin6 = (struct sockaddr_in6 *)&ifr.ifr_addr; 68 sin6 = (struct sockaddr_in6 *)&ifr.ifr_addr;
68 sin6->sin6_family = AF_INET6; 69 sin6->sin6_family = AF_INET6;
69 sin6->sin6_len = sizeof(*sin6); 70 sin6->sin6_len = sizeof(*sin6);
70 rv = inet_pton(AF_INET6, argv[ARG_ADDR], &sin6->sin6_addr); 71 rv = inet_pton(AF_INET6, argv[ARG_ADDR], &sin6->sin6_addr);
71 72
72 if (rv != 1) 73 if (rv != 1)