4 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 145
145
* </tr>
146
146
*
147
147
* <tr>
148
+ * <th scope="row">setSocketImpl</th>
149
+ * <td>The ability to create a sub-class of Socket or ServerSocket with a
150
+ * user specified SocketImpl.</td>
151
+ * <td>Malicious user-defined SocketImpls can change the behavior of
152
+ * Socket and ServerSocket in surprising ways, by virtue of their
153
+ * ability to access the protected fields of SocketImpl.</td>
154
+ * </tr>
155
+ *
156
+ * <tr>
148
157
* <th scope="row">specifyStreamHandler</th>
149
158
* <td>The ability
150
159
* to specify a stream handler when constructing a URL</td>
Original file line number Diff line number Diff line change 32
32
import java .util .Set ;
33
33
import java .util .Collections ;
34
34
35
+ import sun .security .util .SecurityConstants ;
35
36
import sun .net .PlatformSocketImpl ;
36
37
37
38
/**
@@ -73,13 +74,25 @@ class ServerSocket implements java.io.Closeable {
73
74
*
74
75
* @throws NullPointerException if impl is {@code null}.
75
76
*
77
+ * @throws SecurityException if a security manager is set and
78
+ * its {@code checkPermission} method doesn't allow
79
+ * {@code NetPermission("setSocketImpl")}.
76
80
* @since 12
77
81
*/
78
82
protected ServerSocket (SocketImpl impl ) {
79
83
Objects .requireNonNull (impl );
84
+ checkPermission ();
80
85
this .impl = impl ;
81
86
}
82
87
88
+ private static Void checkPermission () {
89
+ SecurityManager sm = System .getSecurityManager ();
90
+ if (sm != null ) {
91
+ sm .checkPermission (SecurityConstants .SET_SOCKETIMPL_PERMISSION );
92
+ }
93
+ return null ;
94
+ }
95
+
83
96
/**
84
97
* Creates an unbound server socket.
85
98
*
Original file line number Diff line number Diff line change 25
25
26
26
package java .net ;
27
27
28
+ import sun .security .util .SecurityConstants ;
29
+
28
30
import java .io .InputStream ;
29
31
import java .io .OutputStream ;
30
32
import java .io .IOException ;
@@ -182,12 +184,28 @@ public Socket(Proxy proxy) {
182
184
*
183
185
* @throws SocketException if there is an error in the underlying protocol,
184
186
* such as a TCP error.
187
+ *
188
+ * @throws SecurityException if {@code impl} is non-null and a security manager is set
189
+ * and its {@code checkPermission} method doesn't allow {@code NetPermission("setSocketImpl")}.
190
+ *
185
191
* @since 1.1
186
192
*/
187
193
protected Socket (SocketImpl impl ) throws SocketException {
194
+ checkPermission (impl );
188
195
this .impl = impl ;
189
196
}
190
197
198
+ private static Void checkPermission (SocketImpl impl ) {
199
+ if (impl == null ) {
200
+ return null ;
201
+ }
202
+ SecurityManager sm = System .getSecurityManager ();
203
+ if (sm != null ) {
204
+ sm .checkPermission (SecurityConstants .SET_SOCKETIMPL_PERMISSION );
205
+ }
206
+ return null ;
207
+ }
208
+
191
209
/**
192
210
* Creates a stream socket and connects it to the specified port
193
211
* number on the named host.
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2003, 2016 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2003, 2019 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -97,6 +97,10 @@ private SecurityConstants () {
97
97
public static final NetPermission GET_RESPONSECACHE_PERMISSION =
98
98
new NetPermission ("getResponseCache" );
99
99
100
+ // java.net.ServerSocket, java.net.Socket
101
+ public static final NetPermission SET_SOCKETIMPL_PERMISSION =
102
+ new NetPermission ("setSocketImpl" );
103
+
100
104
// java.lang.SecurityManager, sun.applet.AppletPanel
101
105
public static final RuntimePermission CREATE_CLASSLOADER_PERMISSION =
102
106
new RuntimePermission ("createClassLoader" );
0 commit comments