| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: uipc_syscalls.c,v 1.188 2017/12/26 08:30:58 kamil Exp $ */ | | 1 | /* $NetBSD: uipc_syscalls.c,v 1.189 2017/12/31 19:39:57 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2008, 2009 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 Andrew Doran. | | 8 | * by Andrew Doran. |
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. |
| @@ -51,27 +51,27 @@ | | | @@ -51,27 +51,27 @@ |
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 | * SUCH DAMAGE. | | 58 | * SUCH DAMAGE. |
59 | * | | 59 | * |
60 | * @(#)uipc_syscalls.c 8.6 (Berkeley) 2/14/95 | | 60 | * @(#)uipc_syscalls.c 8.6 (Berkeley) 2/14/95 |
61 | */ | | 61 | */ |
62 | | | 62 | |
63 | #include <sys/cdefs.h> | | 63 | #include <sys/cdefs.h> |
64 | __KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.188 2017/12/26 08:30:58 kamil Exp $"); | | 64 | __KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.189 2017/12/31 19:39:57 christos Exp $"); |
65 | | | 65 | |
66 | #ifdef _KERNEL_OPT | | 66 | #ifdef _KERNEL_OPT |
67 | #include "opt_pipe.h" | | 67 | #include "opt_pipe.h" |
68 | #endif | | 68 | #endif |
69 | | | 69 | |
70 | #include <sys/param.h> | | 70 | #include <sys/param.h> |
71 | #include <sys/systm.h> | | 71 | #include <sys/systm.h> |
72 | #include <sys/filedesc.h> | | 72 | #include <sys/filedesc.h> |
73 | #include <sys/proc.h> | | 73 | #include <sys/proc.h> |
74 | #include <sys/file.h> | | 74 | #include <sys/file.h> |
75 | #include <sys/buf.h> | | 75 | #include <sys/buf.h> |
76 | #define MBUFTYPES | | 76 | #define MBUFTYPES |
77 | #include <sys/mbuf.h> | | 77 | #include <sys/mbuf.h> |
| @@ -1225,27 +1225,30 @@ sys_getsockopt(struct lwp *l, const stru | | | @@ -1225,27 +1225,30 @@ sys_getsockopt(struct lwp *l, const stru |
1225 | unsigned int valsize, len; | | 1225 | unsigned int valsize, len; |
1226 | int error; | | 1226 | int error; |
1227 | | | 1227 | |
1228 | if (SCARG(uap, val) != NULL) { | | 1228 | if (SCARG(uap, val) != NULL) { |
1229 | error = copyin(SCARG(uap, avalsize), &valsize, sizeof(valsize)); | | 1229 | error = copyin(SCARG(uap, avalsize), &valsize, sizeof(valsize)); |
1230 | if (error) | | 1230 | if (error) |
1231 | return error; | | 1231 | return error; |
1232 | } else | | 1232 | } else |
1233 | valsize = 0; | | 1233 | valsize = 0; |
1234 | | | 1234 | |
1235 | if ((error = fd_getsock1(SCARG(uap, s), &so, &fp)) != 0) | | 1235 | if ((error = fd_getsock1(SCARG(uap, s), &so, &fp)) != 0) |
1236 | return (error); | | 1236 | return (error); |
1237 | | | 1237 | |
1238 | sockopt_init(&sopt, SCARG(uap, level), SCARG(uap, name), 0); | | 1238 | if (valsize > MCLBYTES) |
| | | 1239 | return EINVAL; |
| | | 1240 | |
| | | 1241 | sockopt_init(&sopt, SCARG(uap, level), SCARG(uap, name), valsize); |
1239 | | | 1242 | |
1240 | if (fp->f_flag & FNOSIGPIPE) | | 1243 | if (fp->f_flag & FNOSIGPIPE) |
1241 | so->so_options |= SO_NOSIGPIPE; | | 1244 | so->so_options |= SO_NOSIGPIPE; |
1242 | else | | 1245 | else |
1243 | so->so_options &= ~SO_NOSIGPIPE; | | 1246 | so->so_options &= ~SO_NOSIGPIPE; |
1244 | error = sogetopt(so, &sopt); | | 1247 | error = sogetopt(so, &sopt); |
1245 | if (error) | | 1248 | if (error) |
1246 | goto out; | | 1249 | goto out; |
1247 | | | 1250 | |
1248 | if (valsize > 0) { | | 1251 | if (valsize > 0) { |
1249 | len = min(valsize, sopt.sopt_size); | | 1252 | len = min(valsize, sopt.sopt_size); |
1250 | error = copyout(sopt.sopt_data, SCARG(uap, val), len); | | 1253 | error = copyout(sopt.sopt_data, SCARG(uap, val), len); |
1251 | if (error) | | 1254 | if (error) |