Commit 8fbcc1db authored by hpi1's avatar hpi1

BDJSocketFactory: reflection requires doPrivileged

parent d0b2b9f8
......@@ -28,6 +28,10 @@ import java.net.Socket;
import java.net.SocketImpl;
import java.net.SocketImplFactory;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
class BDJSocketFactory implements SocketImplFactory {
protected static void init() {
......@@ -45,13 +49,18 @@ class BDJSocketFactory implements SocketImplFactory {
private SocketImpl newSocket() {
try {
Class defaultSocketImpl = Class.forName("java.net.SocksSocketImpl");
Constructor constructor = defaultSocketImpl.getDeclaredConstructor/*s*/(new Class[0])/*[0]*/;
constructor.setAccessible(true);
return (SocketImpl) constructor.newInstance(new Object[0]);
} catch (Exception e) {
logger.error("Failed to create socket: " + e + " at " + Logger.dumpStack());
throw new RuntimeException(e);
return (SocketImpl)AccessController.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws Exception {
Class defaultSocketImpl = Class.forName("java.net.SocksSocketImpl");
Constructor constructor = defaultSocketImpl.getDeclaredConstructor/*s*/(new Class[0])/*[0]*/;
constructor.setAccessible(true);
return constructor.newInstance(new Object[0]);
}
});
} catch (PrivilegedActionException e) {
logger.error("Failed to create socket: " + e.getException() + " at " + Logger.dumpStack());
throw new RuntimeException(e.getException());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment