Author: toad
Date: 2008-05-06 17:12:13 +0000 (Tue, 06 May 2008)
New Revision: 19802

Modified:
   trunk/freenet/src/freenet/io/comm/Peer.java
Log:
Peer: Throw on an invalid port number. Exception depends on the constructor

Modified: trunk/freenet/src/freenet/io/comm/Peer.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/Peer.java 2008-05-06 17:01:14 UTC (rev 
19801)
+++ trunk/freenet/src/freenet/io/comm/Peer.java 2008-05-06 17:12:13 UTC (rev 
19802)
@@ -53,11 +53,13 @@
        public Peer(DataInputStream dis) throws IOException {
                addr = new FreenetInetAddress(dis);
                _port = dis.readInt();
+               if(_port > 65535 || _port < 0) throw new IOException("bogus 
port");
        }

        public Peer(DataInputStream dis, boolean checkHostnameOrIPSyntax) 
throws HostnameSyntaxException, IOException {
                addr = new FreenetInetAddress(dis, checkHostnameOrIPSyntax);
                _port = dis.readInt();
+               if(_port > 65535 || _port < 0) throw new IOException("bogus 
port");
        }

        /**
@@ -68,6 +70,7 @@
        public Peer(InetAddress address, int port) {
                addr = new FreenetInetAddress(address);
                _port = port;
+               if(_port > 65535 || _port < 0) throw new 
IllegalArgumentException("bogus port");
        }

        /**
@@ -91,6 +94,7 @@
         String strport = physical.substring(offset+1);
         try {
             _port = Integer.parseInt(strport);
+            if(_port < 0 || _port > 65535) throw new 
PeerParseException("Invalid port "+_port);
         } catch (NumberFormatException e) {
             throw new PeerParseException(e);
         }
@@ -121,6 +125,7 @@
         String strport = physical.substring(offset+1);
         try {
             _port = Integer.parseInt(strport);
+            if(_port < 0 || _port > 65535) throw new 
PeerParseException("Invalid port "+_port);
         } catch (NumberFormatException e) {
             throw new PeerParseException(e);
         }
@@ -130,6 +135,7 @@
        this.addr = addr;
        if(addr == null) throw new NullPointerException();
        this._port = port;
+               if(_port > 65535 || _port < 0) throw new 
IllegalArgumentException("bogus port");
        }

        public boolean isNull() {


Reply via email to