Fri Jul 17 15:24:49 2020 UTC ()
Pull up following revision(s) (requested by msaitoh in ticket #1018):

	sys/net/if.c: revision 1.479
	sys/compat/common/uipc_syscalls_40.c: revision 1.23
	sys/compat/linux/common/linux_socket.c: revision 1.150
	sys/compat/linux32/common/linux32_socket.c: revision 1.31

 Don't accept negative value.


(martin)
diff -r1.20 -r1.20.2.1 src/sys/compat/common/uipc_syscalls_40.c
diff -r1.145.4.1 -r1.145.4.2 src/sys/compat/linux/common/linux_socket.c
diff -r1.30 -r1.30.4.1 src/sys/compat/linux32/common/linux32_socket.c
diff -r1.457.2.3 -r1.457.2.4 src/sys/net/if.c

cvs diff -r1.20 -r1.20.2.1 src/sys/compat/common/uipc_syscalls_40.c (expand / switch to unified diff)

--- src/sys/compat/common/uipc_syscalls_40.c 2019/04/23 07:45:06 1.20
+++ src/sys/compat/common/uipc_syscalls_40.c 2020/07/17 15:24:48 1.20.2.1
@@ -1,19 +1,19 @@ @@ -1,19 +1,19 @@
1/* $NetBSD: uipc_syscalls_40.c,v 1.20 2019/04/23 07:45:06 msaitoh Exp $ */ 1/* $NetBSD: uipc_syscalls_40.c,v 1.20.2.1 2020/07/17 15:24:48 martin Exp $ */
2 2
3/* written by Pavel Cahyna, 2006. Public domain. */ 3/* written by Pavel Cahyna, 2006. Public domain. */
4 4
5#include <sys/cdefs.h> 5#include <sys/cdefs.h>
6__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.20 2019/04/23 07:45:06 msaitoh Exp $"); 6__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.20.2.1 2020/07/17 15:24:48 martin Exp $");
7 7
8#if defined(_KERNEL_OPT) 8#if defined(_KERNEL_OPT)
9#include "opt_compat_netbsd.h" 9#include "opt_compat_netbsd.h"
10#endif 10#endif
11 11
12/* 12/*
13 * System call interface to the socket abstraction. 13 * System call interface to the socket abstraction.
14 */ 14 */
15 15
16#include <sys/param.h> 16#include <sys/param.h>
17#include <sys/kernel.h> 17#include <sys/kernel.h>
18#include <sys/msg.h> 18#include <sys/msg.h>
19#include <sys/sysctl.h> 19#include <sys/sysctl.h>
@@ -44,31 +44,34 @@ compat_ifconf(u_long cmd, void *data) @@ -44,31 +44,34 @@ compat_ifconf(u_long cmd, void *data)
44 const bool docopy = ifc->ifc_req != NULL; 44 const bool docopy = ifc->ifc_req != NULL;
45 int s; 45 int s;
46 int bound; 46 int bound;
47 struct psref psref; 47 struct psref psref;
48 48
49 switch (cmd) { 49 switch (cmd) {
50 case OSIOCGIFCONF: 50 case OSIOCGIFCONF:
51 case OOSIOCGIFCONF: 51 case OOSIOCGIFCONF:
52 break; 52 break;
53 default: 53 default:
54 return ENOSYS; 54 return ENOSYS;
55 } 55 }
56 56
57 memset(&ifr, 0, sizeof(ifr)); 
58 if (docopy) { 57 if (docopy) {
 58 if (ifc->ifc_len < 0)
 59 return EINVAL;
 60
59 space = ifc->ifc_len; 61 space = ifc->ifc_len;
60 ifrp = ifc->ifc_req; 62 ifrp = ifc->ifc_req;
61 } 63 }
 64 memset(&ifr, 0, sizeof(ifr));
62 65
63 bound = curlwp_bind(); 66 bound = curlwp_bind();
64 s = pserialize_read_enter(); 67 s = pserialize_read_enter();
65 IFNET_READER_FOREACH(ifp) { 68 IFNET_READER_FOREACH(ifp) {
66 struct ifaddr *ifa; 69 struct ifaddr *ifa;
67 70
68 if_acquire(ifp, &psref); 71 if_acquire(ifp, &psref);
69 pserialize_read_exit(s); 72 pserialize_read_exit(s);
70 73
71 (void)strncpy(ifr.ifr_name, ifp->if_xname, 74 (void)strncpy(ifr.ifr_name, ifp->if_xname,
72 sizeof(ifr.ifr_name)); 75 sizeof(ifr.ifr_name));
73 if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') { 76 if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') {
74 error = ENAMETOOLONG; 77 error = ENAMETOOLONG;

cvs diff -r1.145.4.1 -r1.145.4.2 src/sys/compat/linux/common/linux_socket.c (expand / switch to unified diff)

--- src/sys/compat/linux/common/linux_socket.c 2019/09/13 06:25:25 1.145.4.1
+++ src/sys/compat/linux/common/linux_socket.c 2020/07/17 15:24:48 1.145.4.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: linux_socket.c,v 1.145.4.1 2019/09/13 06:25:25 martin Exp $ */ 1/* $NetBSD: linux_socket.c,v 1.145.4.2 2020/07/17 15:24:48 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1995, 1998, 2008 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 Frank van der Linden and Eric Haszlakiewicz. 8 * by Frank van der Linden and Eric Haszlakiewicz.
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.
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * Functions in multiarch: 33 * Functions in multiarch:
34 * linux_sys_socketcall : linux_socketcall.c 34 * linux_sys_socketcall : linux_socketcall.c
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.145.4.1 2019/09/13 06:25:25 martin Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.145.4.2 2020/07/17 15:24:48 martin Exp $");
39 39
40#if defined(_KERNEL_OPT) 40#if defined(_KERNEL_OPT)
41#include "opt_inet.h" 41#include "opt_inet.h"
42#endif /* defined(_KERNEL_OPT) */ 42#endif /* defined(_KERNEL_OPT) */
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/kernel.h> 45#include <sys/kernel.h>
46#include <sys/systm.h> 46#include <sys/systm.h>
47#include <sys/buf.h> 47#include <sys/buf.h>
48#include <sys/ioctl.h> 48#include <sys/ioctl.h>
49#include <sys/tty.h> 49#include <sys/tty.h>
50#include <sys/file.h> 50#include <sys/file.h>
51#include <sys/filedesc.h> 51#include <sys/filedesc.h>
@@ -1130,32 +1130,35 @@ linux_getifconf(struct lwp *l, register_ @@ -1130,32 +1130,35 @@ linux_getifconf(struct lwp *l, register_
1130 struct sockaddr *sa; 1130 struct sockaddr *sa;
1131 struct osockaddr *osa; 1131 struct osockaddr *osa;
1132 int space = 0, error; 1132 int space = 0, error;
1133 const int sz = (int)sizeof(ifr); 1133 const int sz = (int)sizeof(ifr);
1134 bool docopy; 1134 bool docopy;
1135 int s; 1135 int s;
1136 int bound; 1136 int bound;
1137 struct psref psref; 1137 struct psref psref;
1138 1138
1139 error = copyin(data, &ifc, sizeof(ifc)); 1139 error = copyin(data, &ifc, sizeof(ifc));
1140 if (error) 1140 if (error)
1141 return error; 1141 return error;
1142 1142
1143 memset(&ifr, 0, sizeof(ifr)); 
1144 docopy = ifc.ifc_req != NULL; 1143 docopy = ifc.ifc_req != NULL;
1145 if (docopy) { 1144 if (docopy) {
 1145 if (ifc.ifc_len < 0)
 1146 return EINVAL;
 1147
1146 space = ifc.ifc_len; 1148 space = ifc.ifc_len;
1147 ifrp = ifc.ifc_req; 1149 ifrp = ifc.ifc_req;
1148 } 1150 }
 1151 memset(&ifr, 0, sizeof(ifr));
1149 1152
1150 bound = curlwp_bind(); 1153 bound = curlwp_bind();
1151 s = pserialize_read_enter(); 1154 s = pserialize_read_enter();
1152 IFNET_READER_FOREACH(ifp) { 1155 IFNET_READER_FOREACH(ifp) {
1153 struct ifaddr *ifa; 1156 struct ifaddr *ifa;
1154 if_acquire(ifp, &psref); 1157 if_acquire(ifp, &psref);
1155 pserialize_read_exit(s); 1158 pserialize_read_exit(s);
1156 1159
1157 (void)strncpy(ifr.ifr_name, ifp->if_xname, 1160 (void)strncpy(ifr.ifr_name, ifp->if_xname,
1158 sizeof(ifr.ifr_name)); 1161 sizeof(ifr.ifr_name));
1159 if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') { 1162 if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') {
1160 error = ENAMETOOLONG; 1163 error = ENAMETOOLONG;
1161 goto release_exit; 1164 goto release_exit;

cvs diff -r1.30 -r1.30.4.1 src/sys/compat/linux32/common/linux32_socket.c (expand / switch to unified diff)

--- src/sys/compat/linux32/common/linux32_socket.c 2019/04/18 17:45:12 1.30
+++ src/sys/compat/linux32/common/linux32_socket.c 2020/07/17 15:24:49 1.30.4.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: linux32_socket.c,v 1.30 2019/04/18 17:45:12 christos Exp $ */ 1/* $NetBSD: linux32_socket.c,v 1.30.4.1 2020/07/17 15:24:49 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. 4 * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software 14 * 3. All advertising materials mentioning features or use of this software
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS  24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE. 31 * POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35 35
36__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.30 2019/04/18 17:45:12 christos Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.30.4.1 2020/07/17 15:24:49 martin Exp $");
37 37
38#include <sys/types.h> 38#include <sys/types.h>
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/fstypes.h> 40#include <sys/fstypes.h>
41#include <sys/signal.h> 41#include <sys/signal.h>
42#include <sys/dirent.h> 42#include <sys/dirent.h>
43#include <sys/kernel.h> 43#include <sys/kernel.h>
44#include <sys/fcntl.h> 44#include <sys/fcntl.h>
45#include <sys/select.h> 45#include <sys/select.h>
46#include <sys/proc.h> 46#include <sys/proc.h>
47#include <sys/ucred.h> 47#include <sys/ucred.h>
48#include <sys/swap.h> 48#include <sys/swap.h>
49#include <sys/file.h> 49#include <sys/file.h>
@@ -421,32 +421,35 @@ linux32_getifconf(struct lwp *l, registe @@ -421,32 +421,35 @@ linux32_getifconf(struct lwp *l, registe
421 struct sockaddr *sa; 421 struct sockaddr *sa;
422 struct osockaddr *osa; 422 struct osockaddr *osa;
423 int space = 0, error; 423 int space = 0, error;
424 const int sz = (int)sizeof(ifr); 424 const int sz = (int)sizeof(ifr);
425 bool docopy; 425 bool docopy;
426 int s; 426 int s;
427 int bound; 427 int bound;
428 struct psref psref; 428 struct psref psref;
429 429
430 error = copyin(data, &ifc, sizeof(ifc)); 430 error = copyin(data, &ifc, sizeof(ifc));
431 if (error) 431 if (error)
432 return error; 432 return error;
433 433
434 memset(&ifr, 0, sizeof(ifr)); 
435 docopy = NETBSD32PTR64(ifc.ifc_req) != NULL; 434 docopy = NETBSD32PTR64(ifc.ifc_req) != NULL;
436 if (docopy) { 435 if (docopy) {
 436 if (ifc.ifc_len < 0)
 437 return EINVAL;
 438
437 space = ifc.ifc_len; 439 space = ifc.ifc_len;
438 ifrp = NETBSD32PTR64(ifc.ifc_req); 440 ifrp = NETBSD32PTR64(ifc.ifc_req);
439 } 441 }
 442 memset(&ifr, 0, sizeof(ifr));
440 443
441 bound = curlwp_bind(); 444 bound = curlwp_bind();
442 s = pserialize_read_enter(); 445 s = pserialize_read_enter();
443 IFNET_READER_FOREACH(ifp) { 446 IFNET_READER_FOREACH(ifp) {
444 struct ifaddr *ifa; 447 struct ifaddr *ifa;
445 if_acquire(ifp, &psref); 448 if_acquire(ifp, &psref);
446 pserialize_read_exit(s); 449 pserialize_read_exit(s);
447 450
448 (void)strncpy(ifr.ifr_name, ifp->if_xname, 451 (void)strncpy(ifr.ifr_name, ifp->if_xname,
449 sizeof(ifr.ifr_name)); 452 sizeof(ifr.ifr_name));
450 if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') { 453 if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') {
451 error = ENAMETOOLONG; 454 error = ENAMETOOLONG;
452 goto release_exit; 455 goto release_exit;

cvs diff -r1.457.2.3 -r1.457.2.4 src/sys/net/if.c (expand / switch to unified diff)

--- src/sys/net/if.c 2019/12/17 16:12:54 1.457.2.3
+++ src/sys/net/if.c 2020/07/17 15:24:48 1.457.2.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if.c,v 1.457.2.3 2019/12/17 16:12:54 martin Exp $ */ 1/* $NetBSD: if.c,v 1.457.2.4 2020/07/17 15:24:48 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2008 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 William Studenmund and Jason R. Thorpe. 8 * by William Studenmund and Jason R. Thorpe.
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.
@@ -80,27 +80,27 @@ @@ -80,27 +80,27 @@
80 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 80 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
81 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 81 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
82 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 82 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
83 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 83 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
84 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 84 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
85 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 85 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
86 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 86 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
87 * SUCH DAMAGE. 87 * SUCH DAMAGE.
88 * 88 *
89 * @(#)if.c 8.5 (Berkeley) 1/9/95 89 * @(#)if.c 8.5 (Berkeley) 1/9/95
90 */ 90 */
91 91
92#include <sys/cdefs.h> 92#include <sys/cdefs.h>
93__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.457.2.3 2019/12/17 16:12:54 martin Exp $"); 93__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.457.2.4 2020/07/17 15:24:48 martin Exp $");
94 94
95#if defined(_KERNEL_OPT) 95#if defined(_KERNEL_OPT)
96#include "opt_inet.h" 96#include "opt_inet.h"
97#include "opt_ipsec.h" 97#include "opt_ipsec.h"
98#include "opt_atalk.h" 98#include "opt_atalk.h"
99#include "opt_wlan.h" 99#include "opt_wlan.h"
100#include "opt_net_mpsafe.h" 100#include "opt_net_mpsafe.h"
101#include "opt_mrouting.h" 101#include "opt_mrouting.h"
102#endif 102#endif
103 103
104#include <sys/param.h> 104#include <sys/param.h>
105#include <sys/mbuf.h> 105#include <sys/mbuf.h>
106#include <sys/systm.h> 106#include <sys/systm.h>
@@ -3455,31 +3455,34 @@ static int @@ -3455,31 +3455,34 @@ static int
3455ifconf(u_long cmd, void *data) 3455ifconf(u_long cmd, void *data)
3456{ 3456{
3457 struct ifconf *ifc = (struct ifconf *)data; 3457 struct ifconf *ifc = (struct ifconf *)data;
3458 struct ifnet *ifp; 3458 struct ifnet *ifp;
3459 struct ifaddr *ifa; 3459 struct ifaddr *ifa;
3460 struct ifreq ifr, *ifrp = NULL; 3460 struct ifreq ifr, *ifrp = NULL;
3461 int space = 0, error = 0; 3461 int space = 0, error = 0;
3462 const int sz = (int)sizeof(struct ifreq); 3462 const int sz = (int)sizeof(struct ifreq);
3463 const bool docopy = ifc->ifc_req != NULL; 3463 const bool docopy = ifc->ifc_req != NULL;
3464 int s; 3464 int s;
3465 int bound; 3465 int bound;
3466 struct psref psref; 3466 struct psref psref;
3467 3467
3468 memset(&ifr, 0, sizeof(ifr)); 
3469 if (docopy) { 3468 if (docopy) {
 3469 if (ifc->ifc_len < 0)
 3470 return EINVAL;
 3471
3470 space = ifc->ifc_len; 3472 space = ifc->ifc_len;
3471 ifrp = ifc->ifc_req; 3473 ifrp = ifc->ifc_req;
3472 } 3474 }
 3475 memset(&ifr, 0, sizeof(ifr));
3473 3476
3474 bound = curlwp_bind(); 3477 bound = curlwp_bind();
3475 s = pserialize_read_enter(); 3478 s = pserialize_read_enter();
3476 IFNET_READER_FOREACH(ifp) { 3479 IFNET_READER_FOREACH(ifp) {
3477 psref_acquire(&psref, &ifp->if_psref, ifnet_psref_class); 3480 psref_acquire(&psref, &ifp->if_psref, ifnet_psref_class);
3478 pserialize_read_exit(s); 3481 pserialize_read_exit(s);
3479 3482
3480 (void)strncpy(ifr.ifr_name, ifp->if_xname, 3483 (void)strncpy(ifr.ifr_name, ifp->if_xname,
3481 sizeof(ifr.ifr_name)); 3484 sizeof(ifr.ifr_name));
3482 if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') { 3485 if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') {
3483 error = ENAMETOOLONG; 3486 error = ENAMETOOLONG;
3484 goto release_exit; 3487 goto release_exit;
3485 } 3488 }