45984
|
1 |
/*
|
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.rmi.transport;
|
|
27 |
|
|
28 |
import java.io.ObjectInputFilter;
|
|
29 |
import java.io.ObjectInputStream;
|
|
30 |
import java.rmi.dgc.Lease;
|
|
31 |
import java.rmi.dgc.VMID;
|
|
32 |
import java.rmi.server.UID;
|
|
33 |
import java.security.AccessController;
|
|
34 |
import java.security.PrivilegedAction;
|
|
35 |
|
|
36 |
import sun.rmi.server.UnicastRef;
|
|
37 |
import sun.rmi.transport.tcp.TCPConnection;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Stubs to invoke DGC remote methods.
|
|
41 |
* Originally generated from RMIC but frozen to insert serialFilter.
|
|
42 |
*/
|
|
43 |
@SuppressWarnings({"deprecation", "serial"})
|
|
44 |
public final class DGCImpl_Stub
|
|
45 |
extends java.rmi.server.RemoteStub
|
|
46 |
implements java.rmi.dgc.DGC {
|
|
47 |
private static final java.rmi.server.Operation[] operations = {
|
|
48 |
new java.rmi.server.Operation("void clean(java.rmi.server.ObjID[], long, java.rmi.dgc.VMID, boolean)"),
|
|
49 |
new java.rmi.server.Operation("java.rmi.dgc.Lease dirty(java.rmi.server.ObjID[], long, java.rmi.dgc.Lease)")
|
|
50 |
};
|
|
51 |
|
|
52 |
private static final long interfaceHash = -669196253586618813L;
|
|
53 |
|
|
54 |
/** Registry max depth of remote invocations. **/
|
|
55 |
private static int DGCCLIENT_MAX_DEPTH = 6;
|
|
56 |
|
|
57 |
/** Registry maximum array size in remote invocations. **/
|
|
58 |
private static int DGCCLIENT_MAX_ARRAY_SIZE = 10000;
|
|
59 |
|
|
60 |
// constructors
|
|
61 |
public DGCImpl_Stub() {
|
|
62 |
super();
|
|
63 |
}
|
|
64 |
|
|
65 |
public DGCImpl_Stub(java.rmi.server.RemoteRef ref) {
|
|
66 |
super(ref);
|
|
67 |
}
|
|
68 |
|
|
69 |
// methods from remote interfaces
|
|
70 |
|
|
71 |
// implementation of clean(ObjID[], long, VMID, boolean)
|
|
72 |
public void clean(java.rmi.server.ObjID[] $param_arrayOf_ObjID_1, long $param_long_2, java.rmi.dgc.VMID $param_VMID_3, boolean $param_boolean_4)
|
|
73 |
throws java.rmi.RemoteException {
|
|
74 |
try {
|
|
75 |
java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 0, interfaceHash);
|
|
76 |
try {
|
|
77 |
java.io.ObjectOutput out = call.getOutputStream();
|
|
78 |
out.writeObject($param_arrayOf_ObjID_1);
|
|
79 |
out.writeLong($param_long_2);
|
|
80 |
out.writeObject($param_VMID_3);
|
|
81 |
out.writeBoolean($param_boolean_4);
|
|
82 |
} catch (java.io.IOException e) {
|
|
83 |
throw new java.rmi.MarshalException("error marshalling arguments", e);
|
|
84 |
}
|
|
85 |
ref.invoke(call);
|
|
86 |
ref.done(call);
|
|
87 |
} catch (java.lang.RuntimeException e) {
|
|
88 |
throw e;
|
|
89 |
} catch (java.rmi.RemoteException e) {
|
|
90 |
throw e;
|
|
91 |
} catch (java.lang.Exception e) {
|
|
92 |
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
|
|
93 |
}
|
|
94 |
}
|
|
95 |
|
|
96 |
// implementation of dirty(ObjID[], long, Lease)
|
|
97 |
public java.rmi.dgc.Lease dirty(java.rmi.server.ObjID[] $param_arrayOf_ObjID_1, long $param_long_2, java.rmi.dgc.Lease $param_Lease_3)
|
|
98 |
throws java.rmi.RemoteException {
|
|
99 |
try {
|
|
100 |
java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 1, interfaceHash);
|
|
101 |
try {
|
|
102 |
java.io.ObjectOutput out = call.getOutputStream();
|
|
103 |
out.writeObject($param_arrayOf_ObjID_1);
|
|
104 |
out.writeLong($param_long_2);
|
|
105 |
out.writeObject($param_Lease_3);
|
|
106 |
} catch (java.io.IOException e) {
|
|
107 |
throw new java.rmi.MarshalException("error marshalling arguments", e);
|
|
108 |
}
|
|
109 |
ref.invoke(call);
|
|
110 |
java.rmi.dgc.Lease $result;
|
|
111 |
Connection connection = ((StreamRemoteCall) call).getConnection();
|
|
112 |
try {
|
|
113 |
java.io.ObjectInput in = call.getInputStream();
|
|
114 |
|
|
115 |
if (in instanceof ObjectInputStream) {
|
|
116 |
/**
|
|
117 |
* Set a filter on the stream for the return value.
|
|
118 |
*/
|
|
119 |
ObjectInputStream ois = (ObjectInputStream) in;
|
|
120 |
AccessController.doPrivileged((PrivilegedAction<Void>)() -> {
|
|
121 |
ois.setObjectInputFilter(DGCImpl_Stub::leaseFilter);
|
|
122 |
return null;
|
|
123 |
});
|
|
124 |
}
|
|
125 |
$result = (java.rmi.dgc.Lease) in.readObject();
|
|
126 |
} catch (java.io.IOException | java.lang.ClassNotFoundException e) {
|
|
127 |
if (connection instanceof TCPConnection) {
|
|
128 |
// Modified to prevent re-use of the connection after an exception
|
|
129 |
((TCPConnection) connection).getChannel().free(connection, false);
|
|
130 |
}
|
|
131 |
throw new java.rmi.UnmarshalException("error unmarshalling return", e);
|
|
132 |
} finally {
|
|
133 |
ref.done(call);
|
|
134 |
}
|
|
135 |
return $result;
|
|
136 |
} catch (java.lang.RuntimeException e) {
|
|
137 |
throw e;
|
|
138 |
} catch (java.rmi.RemoteException e) {
|
|
139 |
throw e;
|
|
140 |
} catch (java.lang.Exception e) {
|
|
141 |
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
|
|
142 |
}
|
|
143 |
}
|
|
144 |
|
|
145 |
/**
|
|
146 |
* ObjectInputFilter to filter DGCClient return value (a Lease).
|
|
147 |
* The list of acceptable classes is very short and explicit.
|
|
148 |
* The depth and array sizes are limited.
|
|
149 |
*
|
|
150 |
* @param filterInfo access to class, arrayLength, etc.
|
|
151 |
* @return {@link ObjectInputFilter.Status#ALLOWED} if allowed,
|
|
152 |
* {@link ObjectInputFilter.Status#REJECTED} if rejected,
|
|
153 |
* otherwise {@link ObjectInputFilter.Status#UNDECIDED}
|
|
154 |
*/
|
|
155 |
private static ObjectInputFilter.Status leaseFilter(ObjectInputFilter.FilterInfo filterInfo) {
|
|
156 |
|
|
157 |
if (filterInfo.depth() > DGCCLIENT_MAX_DEPTH) {
|
|
158 |
return ObjectInputFilter.Status.REJECTED;
|
|
159 |
}
|
|
160 |
Class<?> clazz = filterInfo.serialClass();
|
|
161 |
if (clazz != null) {
|
|
162 |
while (clazz.isArray()) {
|
|
163 |
if (filterInfo.arrayLength() >= 0 && filterInfo.arrayLength() > DGCCLIENT_MAX_ARRAY_SIZE) {
|
|
164 |
return ObjectInputFilter.Status.REJECTED;
|
|
165 |
}
|
|
166 |
// Arrays are allowed depending on the component type
|
|
167 |
clazz = clazz.getComponentType();
|
|
168 |
}
|
|
169 |
if (clazz.isPrimitive()) {
|
|
170 |
// Arrays of primitives are allowed
|
|
171 |
return ObjectInputFilter.Status.ALLOWED;
|
|
172 |
}
|
|
173 |
return (clazz == UID.class ||
|
|
174 |
clazz == VMID.class ||
|
|
175 |
clazz == Lease.class)
|
|
176 |
? ObjectInputFilter.Status.ALLOWED
|
|
177 |
: ObjectInputFilter.Status.REJECTED;
|
|
178 |
}
|
|
179 |
// Not a class, not size limited
|
|
180 |
return ObjectInputFilter.Status.UNDECIDED;
|
|
181 |
}
|
|
182 |
|
|
183 |
}
|