Mon Oct 27 20:03:07 2008 UTC ()
sockopt_getmbuf() may fail, handle that possibility


(plunky)
diff -r1.134 -r1.135 src/sys/netinet6/ip6_output.c

cvs diff -r1.134 -r1.135 src/sys/netinet6/ip6_output.c (expand / switch to unified diff)

--- src/sys/netinet6/ip6_output.c 2008/10/12 15:24:10 1.134
+++ src/sys/netinet6/ip6_output.c 2008/10/27 20:03:07 1.135
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ip6_output.c,v 1.134 2008/10/12 15:24:10 plunky Exp $ */ 1/* $NetBSD: ip6_output.c,v 1.135 2008/10/27 20:03:07 plunky Exp $ */
2/* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ 2/* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -52,27 +52,27 @@ @@ -52,27 +52,27 @@
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE. 59 * SUCH DAMAGE.
60 * 60 *
61 * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 61 * @(#)ip_output.c 8.3 (Berkeley) 1/21/94
62 */ 62 */
63 63
64#include <sys/cdefs.h> 64#include <sys/cdefs.h>
65__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.134 2008/10/12 15:24:10 plunky Exp $"); 65__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.135 2008/10/27 20:03:07 plunky Exp $");
66 66
67#include "opt_inet.h" 67#include "opt_inet.h"
68#include "opt_inet6.h" 68#include "opt_inet6.h"
69#include "opt_ipsec.h" 69#include "opt_ipsec.h"
70#include "opt_pfil_hooks.h" 70#include "opt_pfil_hooks.h"
71 71
72#include <sys/param.h> 72#include <sys/param.h>
73#include <sys/malloc.h> 73#include <sys/malloc.h>
74#include <sys/mbuf.h> 74#include <sys/mbuf.h>
75#include <sys/errno.h> 75#include <sys/errno.h>
76#include <sys/protosw.h> 76#include <sys/protosw.h>
77#include <sys/socket.h> 77#include <sys/socket.h>
78#include <sys/socketvar.h> 78#include <sys/socketvar.h>
@@ -2144,26 +2144,31 @@ ip6_pcbopts(struct ip6_pktopts **pktopt, @@ -2144,26 +2144,31 @@ ip6_pcbopts(struct ip6_pktopts **pktopt,
2144 * Only turning off any previous options, regardless of 2144 * Only turning off any previous options, regardless of
2145 * whether the opt is just created or given. 2145 * whether the opt is just created or given.
2146 */ 2146 */
2147 free(opt, M_IP6OPT); 2147 free(opt, M_IP6OPT);
2148 return (0); 2148 return (0);
2149 } 2149 }
2150 2150
2151 /* set options specified by user. */ 2151 /* set options specified by user. */
2152 if (l && !kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER, 2152 if (l && !kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
2153 NULL)) 2153 NULL))
2154 priv = 1; 2154 priv = 1;
2155 2155
2156 m = sockopt_getmbuf(sopt); 2156 m = sockopt_getmbuf(sopt);
 2157 if (m == NULL) {
 2158 free(opt, M_IP6OPT);
 2159 return (ENOBUFS);
 2160 }
 2161
2157 error = ip6_setpktopts(m, opt, NULL, priv, so->so_proto->pr_protocol); 2162 error = ip6_setpktopts(m, opt, NULL, priv, so->so_proto->pr_protocol);
2158 m_freem(m); 2163 m_freem(m);
2159 if (error != 0) { 2164 if (error != 0) {
2160 ip6_clearpktopts(opt, -1); /* XXX: discard all options */ 2165 ip6_clearpktopts(opt, -1); /* XXX: discard all options */
2161 free(opt, M_IP6OPT); 2166 free(opt, M_IP6OPT);
2162 return (error); 2167 return (error);
2163 } 2168 }
2164 *pktopt = opt; 2169 *pktopt = opt;
2165 return (0); 2170 return (0);
2166} 2171}
2167#endif 2172#endif
2168 2173
2169/* 2174/*