This patch adds a missing SecurityManager check reported in PR42390.

2011-03-14  Andrew John Hughes  <ahug...@redhat.com>

        PR classpath/42390
        * java/net/Socket.java:
        (connect(SocketAddress, int)): Add missing call
        to SecurityManager.

-- 
Andrew :)

Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)

Support Free Java!
Contribute to GNU Classpath and IcedTea
http://www.gnu.org/software/classpath
http://icedtea.classpath.org
PGP Key: F5862A37 (https://keys.indymedia.org/)
Fingerprint = EA30 D855 D50F 90CD F54D  0698 0713 C3ED F586 2A37
Index: java/net/Socket.java
===================================================================
RCS file: /sources/classpath/classpath/java/net/Socket.java,v
retrieving revision 1.65
diff -u -u -r1.65 Socket.java
--- java/net/Socket.java        3 Jun 2010 19:13:02 -0000       1.65
+++ java/net/Socket.java        15 Mar 2011 10:50:37 -0000
@@ -428,7 +428,9 @@
    * @exception IllegalBlockingModeException If this socket has an associated
    * channel, and the channel is in non-blocking mode
    * @exception SocketTimeoutException If the timeout is reached
-   *
+   * @throws SecurityException if the SocketAddress is an {@link 
InetSocketAddress}
+   *                           and a security manager is present which does not
+   *                           allow connections on the given host and port.
    * @since 1.4
    */
   public void connect(SocketAddress endpoint, int timeout)
@@ -440,6 +442,13 @@
     if (! (endpoint instanceof InetSocketAddress))
       throw new IllegalArgumentException("unsupported address type");
 
+    SecurityManager sm = System.getSecurityManager();
+    if (sm != null)
+      {
+        InetSocketAddress inetAddr = (InetSocketAddress) endpoint;
+        sm.checkConnect(inetAddr.getHostName(), inetAddr.getPort());
+      }
+
     // The Sun spec says that if we have an associated channel and
     // it is in non-blocking mode, we throw an IllegalBlockingModeException.
     // However, in our implementation if the channel itself initiated this

Reply via email to