Chromium Code Reviews| Index: runtime/bin/socket_patch.dart |
| diff --git a/runtime/bin/socket_patch.dart b/runtime/bin/socket_patch.dart |
| index 0244e791c190d4d50a114dd4f7e335145516bb6f..664f4dde1edb47258310efa9aa51cfc1be9b1d4f 100644 |
| --- a/runtime/bin/socket_patch.dart |
| +++ b/runtime/bin/socket_patch.dart |
| @@ -387,6 +387,9 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { |
| } |
| static Future<_NativeSocket> connect(host, int port, sourceAddress) { |
| + if ((port == null) || (port < 0) || (port > 0xffff)) { |
| + throw new ArgumentError("Invalid port $port"); |
| + } |
| if (sourceAddress != null && sourceAddress is! _InternetAddress) { |
| if (sourceAddress is String) { |
| sourceAddress = new InternetAddress(sourceAddress); |
| @@ -488,6 +491,9 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { |
| int backlog, |
| bool v6Only, |
| bool shared) { |
| + if ((port == null) || (port < 0) || (port > 0xffff)) { |
| + throw new ArgumentError("Invalid port $port"); |
| + } |
| return new Future.value(host) |
| .then((host) { |
| if (host is _InternetAddress) return host; |
| @@ -526,6 +532,9 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { |
| static Future<_NativeSocket> bindDatagram( |
| host, int port, bool reuseAddress) { |
| + if ((port == null) || (port < 0) || (port > 0xffff)) { |
|
Cutch
2016/09/23 18:05:45
this could be factored into:
_throwOnBadPort(port
zra
2016/09/23 18:12:49
Done.
|
| + throw new ArgumentError("Invalid port $port"); |
| + } |
| return new Future.value(host) |
| .then((host) { |
| if (host is _InternetAddress) return host; |
| @@ -676,6 +685,9 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { |
| int send(List<int> buffer, int offset, int bytes, |
| InternetAddress address, int port) { |
| + if ((port == null) || (port < 0) || (port > 0xffff)) { |
| + throw new ArgumentError("Invalid port $port"); |
| + } |
| if (isClosing || isClosed) return 0; |
| _BufferAndStart bufferAndStart = |
| _ensureFastAndSerializableByteData( |
| @@ -1116,8 +1128,9 @@ class _RawServerSocket extends Stream<RawSocket> |
| int backlog, |
| bool v6Only, |
| bool shared) { |
| - if (port < 0 || port > 0xFFFF) |
| + if ((port == null) || (port < 0) || (port > 0xFFFF)) { |
| throw new ArgumentError("Invalid port $port"); |
| + } |
| if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); |
| return _NativeSocket.bind(address, port, backlog, v6Only, shared) |
| .then((socket) => new _RawServerSocket(socket, v6Only)); |
| @@ -1762,8 +1775,9 @@ class _RawDatagramSocket extends Stream implements RawDatagramSocket { |
| static Future<RawDatagramSocket> bind( |
| host, int port, bool reuseAddress) { |
| - if (port < 0 || port > 0xffff) |
| + if ((port == null) || (port < 0) || (port > 0xffff)) { |
| throw new ArgumentError("Invalid port $port"); |
| + } |
| return _NativeSocket.bindDatagram(host, port, reuseAddress) |
| .then((socket) => new _RawDatagramSocket(socket)); |
| } |