Validate the port values passed to connect(to:port:) function and ensure they fall within the proper range.

This commit is contained in:
Bill Abt
2017-03-27 12:44:34 -04:00
parent f9b590fd03
commit c9ff50a4fa
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -157,7 +157,7 @@ When a listening socket detects an incoming connection request, control is retur
### Connecting a socket to a server (TCP/UNIX).
In addition to the `create(connectedUsing:)` factory method described above, **BlueSocket** supports three additional instance functions for connecting a `Socket` instance to a server. They are:
- `connect(to host: String, port: Int32)` - This API allows you to connect to a server based on the `hostname` and `port` you provide.
- `connect(to host: String, port: Int32)` - This API allows you to connect to a server based on the `hostname` and `port` you provide. Note: an `exception` will be thrown by this function if the value of `port` is not in the range `1024-65535`.
- `connect(to path: String)` - This API can only be used with the `.unix` protocol family. It allows you to connect to a server based on the `path` you provide.
- `connect(using signature: Signature)` - This API allows you specify the connection information by providing a `Socket.Signature` instance containing the information. Refer to `Socket.Signature` in *Socket.swift* for more information.
+2 -2
View File
@@ -1669,9 +1669,9 @@ public class Socket: SocketReader, SocketWriter {
throw Error(code: Socket.SOCKET_ERR_INVALID_HOSTNAME, reason: nil)
}
if port == 0 {
if port < 1024 || port > 65535 {
throw Error(code: Socket.SOCKET_ERR_INVALID_PORT, reason: "Connect to port cannot be zero (0).")
throw Error(code: Socket.SOCKET_ERR_INVALID_PORT, reason: "Invalid port specified. Must be between 1024 and 49151.")
}
// Tell the delegate to initialize as a client...