Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(803)

Side by Side Diff: runtime/bin/socket_patch.dart

Issue 2361373003: Throw an ArgumentError if the port is out of range (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/standalone/io/socket_invalid_arguments_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 @patch class RawServerSocket { 5 @patch class RawServerSocket {
6 @patch static Future<RawServerSocket> bind(address, 6 @patch static Future<RawServerSocket> bind(address,
7 int port, 7 int port,
8 {int backlog: 0, 8 {int backlog: 0,
9 bool v6Only: false, 9 bool v6Only: false,
10 bool shared: false}) { 10 bool shared: false}) {
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 name, () => new _NetworkInterface(name, index)); 380 name, () => new _NetworkInterface(name, index));
381 map[name].addresses.add(address); 381 map[name].addresses.add(address);
382 return map; 382 return map;
383 }); 383 });
384 return map.values.toList(); 384 return map.values.toList();
385 } 385 }
386 }); 386 });
387 } 387 }
388 388
389 static Future<_NativeSocket> connect(host, int port, sourceAddress) { 389 static Future<_NativeSocket> connect(host, int port, sourceAddress) {
390 if ((port == null) || (port < 0) || (port > 0xffff)) {
391 throw new ArgumentError("Invalid port $port");
392 }
390 if (sourceAddress != null && sourceAddress is! _InternetAddress) { 393 if (sourceAddress != null && sourceAddress is! _InternetAddress) {
391 if (sourceAddress is String) { 394 if (sourceAddress is String) {
392 sourceAddress = new InternetAddress(sourceAddress); 395 sourceAddress = new InternetAddress(sourceAddress);
393 } 396 }
394 } 397 }
395 return new Future.value(host) 398 return new Future.value(host)
396 .then((host) { 399 .then((host) {
397 if (host is _InternetAddress) return [host]; 400 if (host is _InternetAddress) return [host];
398 return lookup(host) 401 return lookup(host)
399 .then((addresses) { 402 .then((addresses) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 connectNext(); 484 connectNext();
482 return completer.future; 485 return completer.future;
483 }); 486 });
484 } 487 }
485 488
486 static Future<_NativeSocket> bind(host, 489 static Future<_NativeSocket> bind(host,
487 int port, 490 int port,
488 int backlog, 491 int backlog,
489 bool v6Only, 492 bool v6Only,
490 bool shared) { 493 bool shared) {
494 if ((port == null) || (port < 0) || (port > 0xffff)) {
495 throw new ArgumentError("Invalid port $port");
496 }
491 return new Future.value(host) 497 return new Future.value(host)
492 .then((host) { 498 .then((host) {
493 if (host is _InternetAddress) return host; 499 if (host is _InternetAddress) return host;
494 return lookup(host) 500 return lookup(host)
495 .then((list) { 501 .then((list) {
496 if (list.length == 0) { 502 if (list.length == 0) {
497 throw createError(response, "Failed host lookup: '$host'"); 503 throw createError(response, "Failed host lookup: '$host'");
498 } 504 }
499 return list[0]; 505 return list[0];
500 }); 506 });
(...skipping 18 matching lines...) Expand all
519 return socket; 525 return socket;
520 }); 526 });
521 } 527 }
522 528
523 static void setupResourceInfo(_NativeSocket socket) { 529 static void setupResourceInfo(_NativeSocket socket) {
524 socket.resourceInfo = new _SocketResourceInfo(socket); 530 socket.resourceInfo = new _SocketResourceInfo(socket);
525 } 531 }
526 532
527 static Future<_NativeSocket> bindDatagram( 533 static Future<_NativeSocket> bindDatagram(
528 host, int port, bool reuseAddress) { 534 host, int port, bool reuseAddress) {
535 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.
536 throw new ArgumentError("Invalid port $port");
537 }
529 return new Future.value(host) 538 return new Future.value(host)
530 .then((host) { 539 .then((host) {
531 if (host is _InternetAddress) return host; 540 if (host is _InternetAddress) return host;
532 return lookup(host) 541 return lookup(host)
533 .then((list) { 542 .then((list) {
534 if (list.length == 0) { 543 if (list.length == 0) {
535 throw createError(response, "Failed host lookup: '$host'"); 544 throw createError(response, "Failed host lookup: '$host'");
536 } 545 }
537 return list[0]; 546 return list[0];
538 }); 547 });
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 // TODO(ricow): Remove when we track internal and pipe uses. 678 // TODO(ricow): Remove when we track internal and pipe uses.
670 assert(resourceInfo != null || isPipe || isInternal); 679 assert(resourceInfo != null || isPipe || isInternal);
671 if (resourceInfo != null) { 680 if (resourceInfo != null) {
672 resourceInfo.addWrite(result); 681 resourceInfo.addWrite(result);
673 } 682 }
674 return result; 683 return result;
675 } 684 }
676 685
677 int send(List<int> buffer, int offset, int bytes, 686 int send(List<int> buffer, int offset, int bytes,
678 InternetAddress address, int port) { 687 InternetAddress address, int port) {
688 if ((port == null) || (port < 0) || (port > 0xffff)) {
689 throw new ArgumentError("Invalid port $port");
690 }
679 if (isClosing || isClosed) return 0; 691 if (isClosing || isClosed) return 0;
680 _BufferAndStart bufferAndStart = 692 _BufferAndStart bufferAndStart =
681 _ensureFastAndSerializableByteData( 693 _ensureFastAndSerializableByteData(
682 buffer, offset, bytes); 694 buffer, offset, bytes);
683 var result = nativeSendTo( 695 var result = nativeSendTo(
684 bufferAndStart.buffer, bufferAndStart.start, bytes, 696 bufferAndStart.buffer, bufferAndStart.start, bytes,
685 address._in_addr, port); 697 address._in_addr, port);
686 if (result is OSError) { 698 if (result is OSError) {
687 scheduleMicrotask(() => reportError(result, "Send failed")); 699 scheduleMicrotask(() => reportError(result, "Send failed"));
688 result = 0; 700 result = 0;
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 final _NativeSocket _socket; 1121 final _NativeSocket _socket;
1110 StreamController<RawSocket> _controller; 1122 StreamController<RawSocket> _controller;
1111 ReceivePort _referencePort; 1123 ReceivePort _referencePort;
1112 bool _v6Only; 1124 bool _v6Only;
1113 1125
1114 static Future<_RawServerSocket> bind(address, 1126 static Future<_RawServerSocket> bind(address,
1115 int port, 1127 int port,
1116 int backlog, 1128 int backlog,
1117 bool v6Only, 1129 bool v6Only,
1118 bool shared) { 1130 bool shared) {
1119 if (port < 0 || port > 0xFFFF) 1131 if ((port == null) || (port < 0) || (port > 0xFFFF)) {
1120 throw new ArgumentError("Invalid port $port"); 1132 throw new ArgumentError("Invalid port $port");
1133 }
1121 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); 1134 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog");
1122 return _NativeSocket.bind(address, port, backlog, v6Only, shared) 1135 return _NativeSocket.bind(address, port, backlog, v6Only, shared)
1123 .then((socket) => new _RawServerSocket(socket, v6Only)); 1136 .then((socket) => new _RawServerSocket(socket, v6Only));
1124 } 1137 }
1125 1138
1126 _RawServerSocket(this._socket, this._v6Only); 1139 _RawServerSocket(this._socket, this._v6Only);
1127 1140
1128 StreamSubscription<RawSocket> listen(void onData(RawSocket event), 1141 StreamSubscription<RawSocket> listen(void onData(RawSocket event),
1129 {Function onError, 1142 {Function onError,
1130 void onDone(), 1143 void onDone(),
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 }, 1768 },
1756 error: zone.bindUnaryCallback((e) { 1769 error: zone.bindUnaryCallback((e) {
1757 _controller.addError(e); 1770 _controller.addError(e);
1758 _socket.close(); 1771 _socket.close();
1759 }) 1772 })
1760 ); 1773 );
1761 } 1774 }
1762 1775
1763 static Future<RawDatagramSocket> bind( 1776 static Future<RawDatagramSocket> bind(
1764 host, int port, bool reuseAddress) { 1777 host, int port, bool reuseAddress) {
1765 if (port < 0 || port > 0xffff) 1778 if ((port == null) || (port < 0) || (port > 0xffff)) {
1766 throw new ArgumentError("Invalid port $port"); 1779 throw new ArgumentError("Invalid port $port");
1780 }
1767 return _NativeSocket.bindDatagram(host, port, reuseAddress) 1781 return _NativeSocket.bindDatagram(host, port, reuseAddress)
1768 .then((socket) => new _RawDatagramSocket(socket)); 1782 .then((socket) => new _RawDatagramSocket(socket));
1769 } 1783 }
1770 1784
1771 StreamSubscription<RawSocketEvent> listen(void onData(RawSocketEvent event), 1785 StreamSubscription<RawSocketEvent> listen(void onData(RawSocketEvent event),
1772 {Function onError, 1786 {Function onError,
1773 void onDone(), 1787 void onDone(),
1774 bool cancelOnError}) { 1788 bool cancelOnError}) {
1775 return _controller.stream.listen( 1789 return _controller.stream.listen(
1776 onData, 1790 onData,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 Datagram _makeDatagram(List<int> data, 1878 Datagram _makeDatagram(List<int> data,
1865 String address, 1879 String address,
1866 List<int> in_addr, 1880 List<int> in_addr,
1867 int port) { 1881 int port) {
1868 return new Datagram( 1882 return new Datagram(
1869 data, 1883 data,
1870 new _InternetAddress(address, null, in_addr), 1884 new _InternetAddress(address, null, in_addr),
1871 port); 1885 port);
1872 } 1886 }
1873 1887
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/socket_invalid_arguments_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698