1 /* |
1 /* |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package sun.rmi.transport; |
26 package sun.rmi.transport; |
27 |
27 |
|
28 import sun.rmi.transport.tcp.TCPConnection; |
|
29 |
|
30 import java.io.IOException; |
28 import java.io.ObjectInputFilter; |
31 import java.io.ObjectInputFilter; |
29 import java.io.ObjectInputStream; |
32 import java.rmi.RemoteException; |
30 import java.rmi.dgc.Lease; |
33 import java.rmi.dgc.Lease; |
31 import java.rmi.dgc.VMID; |
34 import java.rmi.dgc.VMID; |
32 import java.rmi.server.UID; |
35 import java.rmi.server.UID; |
33 import java.security.AccessController; |
36 import java.security.AccessController; |
34 import java.security.PrivilegedAction; |
37 import java.security.PrivilegedAction; |
35 |
38 import java.util.ArrayList; |
36 import sun.rmi.server.UnicastRef; |
|
37 import sun.rmi.transport.tcp.TCPConnection; |
|
38 |
39 |
39 /** |
40 /** |
40 * Stubs to invoke DGC remote methods. |
41 * Stubs to invoke DGC remote methods. |
41 * Originally generated from RMIC but frozen to insert serialFilter. |
42 * Originally generated from RMIC but frozen to insert serialFilter. |
42 */ |
43 */ |
70 |
71 |
71 // implementation of clean(ObjID[], long, VMID, boolean) |
72 // 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 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 throws java.rmi.RemoteException { |
74 try { |
75 try { |
75 java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 0, interfaceHash); |
76 StreamRemoteCall call = (StreamRemoteCall)ref.newCall((java.rmi.server.RemoteObject) this, |
|
77 operations, 0, interfaceHash); |
|
78 call.setObjectInputFilter(DGCImpl_Stub::leaseFilter); |
76 try { |
79 try { |
77 java.io.ObjectOutput out = call.getOutputStream(); |
80 java.io.ObjectOutput out = call.getOutputStream(); |
78 out.writeObject($param_arrayOf_ObjID_1); |
81 out.writeObject($param_arrayOf_ObjID_1); |
79 out.writeLong($param_long_2); |
82 out.writeLong($param_long_2); |
80 out.writeObject($param_VMID_3); |
83 out.writeObject($param_VMID_3); |
95 |
98 |
96 // implementation of dirty(ObjID[], long, Lease) |
99 // 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) |
100 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 { |
101 throws java.rmi.RemoteException { |
99 try { |
102 try { |
100 java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 1, interfaceHash); |
103 StreamRemoteCall call = |
|
104 (StreamRemoteCall)ref.newCall((java.rmi.server.RemoteObject) this, |
|
105 operations, 1, interfaceHash); |
|
106 call.setObjectInputFilter(DGCImpl_Stub::leaseFilter); |
101 try { |
107 try { |
102 java.io.ObjectOutput out = call.getOutputStream(); |
108 java.io.ObjectOutput out = call.getOutputStream(); |
103 out.writeObject($param_arrayOf_ObjID_1); |
109 out.writeObject($param_arrayOf_ObjID_1); |
104 out.writeLong($param_long_2); |
110 out.writeLong($param_long_2); |
105 out.writeObject($param_Lease_3); |
111 out.writeObject($param_Lease_3); |
106 } catch (java.io.IOException e) { |
112 } catch (java.io.IOException e) { |
107 throw new java.rmi.MarshalException("error marshalling arguments", e); |
113 throw new java.rmi.MarshalException("error marshalling arguments", e); |
108 } |
114 } |
109 ref.invoke(call); |
115 ref.invoke(call); |
110 java.rmi.dgc.Lease $result; |
116 java.rmi.dgc.Lease $result; |
111 Connection connection = ((StreamRemoteCall) call).getConnection(); |
117 Connection connection = call.getConnection(); |
112 try { |
118 try { |
113 java.io.ObjectInput in = call.getInputStream(); |
119 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(); |
120 $result = (java.rmi.dgc.Lease) in.readObject(); |
126 } catch (java.io.IOException | java.lang.ClassNotFoundException e) { |
121 } catch (ClassCastException | IOException | ClassNotFoundException e) { |
127 if (connection instanceof TCPConnection) { |
122 if (connection instanceof TCPConnection) { |
128 // Modified to prevent re-use of the connection after an exception |
123 // Modified to prevent re-use of the connection after an exception |
129 ((TCPConnection) connection).getChannel().free(connection, false); |
124 ((TCPConnection) connection).getChannel().free(connection, false); |
130 } |
125 } |
|
126 call.discardPendingRefs(); |
131 throw new java.rmi.UnmarshalException("error unmarshalling return", e); |
127 throw new java.rmi.UnmarshalException("error unmarshalling return", e); |
132 } finally { |
128 } finally { |
133 ref.done(call); |
129 ref.done(call); |
134 } |
130 } |
135 return $result; |
131 return $result; |
144 |
140 |
145 /** |
141 /** |
146 * ObjectInputFilter to filter DGCClient return value (a Lease). |
142 * ObjectInputFilter to filter DGCClient return value (a Lease). |
147 * The list of acceptable classes is very short and explicit. |
143 * The list of acceptable classes is very short and explicit. |
148 * The depth and array sizes are limited. |
144 * The depth and array sizes are limited. |
|
145 * <p> |
|
146 * The filter must accept normal and exception returns. |
|
147 * A DGC server may throw exceptions that may have a cause |
|
148 * and suppressed exceptions. |
|
149 * Only exceptions in {@code java.base} and {@code java.rmi} are allowed. |
149 * |
150 * |
150 * @param filterInfo access to class, arrayLength, etc. |
151 * @param filterInfo access to class, arrayLength, etc. |
151 * @return {@link ObjectInputFilter.Status#ALLOWED} if allowed, |
152 * @return {@link ObjectInputFilter.Status#ALLOWED} if allowed, |
152 * {@link ObjectInputFilter.Status#REJECTED} if rejected, |
153 * {@link ObjectInputFilter.Status#REJECTED} if rejected, |
153 * otherwise {@link ObjectInputFilter.Status#UNDECIDED} |
154 * otherwise {@link ObjectInputFilter.Status#UNDECIDED} |
170 // Arrays of primitives are allowed |
171 // Arrays of primitives are allowed |
171 return ObjectInputFilter.Status.ALLOWED; |
172 return ObjectInputFilter.Status.ALLOWED; |
172 } |
173 } |
173 return (clazz == UID.class || |
174 return (clazz == UID.class || |
174 clazz == VMID.class || |
175 clazz == VMID.class || |
175 clazz == Lease.class) |
176 clazz == Lease.class || |
|
177 (Throwable.class.isAssignableFrom(clazz) && |
|
178 (Object.class.getModule() == clazz.getModule() || |
|
179 RemoteException.class.getModule() == clazz.getModule())) || |
|
180 clazz == StackTraceElement.class || |
|
181 clazz == ArrayList.class || // for suppressed exceptions, if any |
|
182 clazz == Object.class || |
|
183 clazz.getName().equals("java.util.Collections$EmptyList")) |
176 ? ObjectInputFilter.Status.ALLOWED |
184 ? ObjectInputFilter.Status.ALLOWED |
177 : ObjectInputFilter.Status.REJECTED; |
185 : ObjectInputFilter.Status.REJECTED; |
178 } |
186 } |
179 // Not a class, not size limited |
187 // Not a class, not size limited |
180 return ObjectInputFilter.Status.UNDECIDED; |
188 return ObjectInputFilter.Status.UNDECIDED; |