Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 186049d

Browse files
lrhncommit-bot@chromium.org
authored andcommitted
Avoid recursion in secure socket _tryFilter method.
Change-Id: If91859b008c76ed1dd4b86c06a563418757bc109 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180180 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
1 parent 21bc398 commit 186049d

File tree

1 file changed

+48
-47
lines changed

1 file changed

+48
-47
lines changed

sdk/lib/io/secure_socket.dart

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -882,69 +882,70 @@ class _RawSecureSocket extends Stream<RawSocketEvent>
882882
}
883883
}
884884

885-
Future<void> _scheduleFilter() async {
885+
Future<void> _scheduleFilter() {
886886
_filterPending = true;
887887
return _tryFilter();
888888
}
889889

890890
Future<void> _tryFilter() async {
891-
if (_status == closedStatus) {
892-
return;
893-
}
894-
if (!_filterPending || _filterActive) {
895-
return;
896-
}
897-
_filterActive = true;
898-
_filterPending = false;
899-
900891
try {
901-
_filterStatus = await _pushAllFilterStages();
902-
_filterActive = false;
903-
if (_status == closedStatus) {
904-
_secureFilter!.destroy();
905-
_secureFilter = null;
906-
return;
907-
}
908-
_socket.readEventsEnabled = true;
909-
if (_filterStatus.writeEmpty && _closedWrite && !_socketClosedWrite) {
910-
// Checks for and handles all cases of partially closed sockets.
911-
shutdown(SocketDirection.send);
892+
while (true) {
912893
if (_status == closedStatus) {
913894
return;
914895
}
915-
}
916-
if (_filterStatus.readEmpty && _socketClosedRead && !_closedRead) {
917-
if (_status == handshakeStatus) {
918-
_secureFilter!.handshake();
919-
if (_status == handshakeStatus) {
920-
throw new HandshakeException(
921-
'Connection terminated during handshake');
922-
}
896+
if (!_filterPending || _filterActive) {
897+
return;
923898
}
924-
_closeHandler();
925-
}
926-
if (_status == closedStatus) {
927-
return;
928-
}
929-
if (_filterStatus.progress) {
930-
_filterPending = true;
931-
if (_filterStatus.writeEncryptedNoLongerEmpty) {
932-
_writeSocket();
899+
_filterActive = true;
900+
_filterPending = false;
901+
902+
_filterStatus = await _pushAllFilterStages();
903+
_filterActive = false;
904+
if (_status == closedStatus) {
905+
_secureFilter!.destroy();
906+
_secureFilter = null;
907+
return;
933908
}
934-
if (_filterStatus.writePlaintextNoLongerFull) {
935-
_sendWriteEvent();
909+
_socket.readEventsEnabled = true;
910+
if (_filterStatus.writeEmpty && _closedWrite && !_socketClosedWrite) {
911+
// Checks for and handles all cases of partially closed sockets.
912+
shutdown(SocketDirection.send);
913+
if (_status == closedStatus) {
914+
return;
915+
}
936916
}
937-
if (_filterStatus.readEncryptedNoLongerFull) {
938-
_readSocket();
917+
if (_filterStatus.readEmpty && _socketClosedRead && !_closedRead) {
918+
if (_status == handshakeStatus) {
919+
_secureFilter!.handshake();
920+
if (_status == handshakeStatus) {
921+
throw new HandshakeException(
922+
'Connection terminated during handshake');
923+
}
924+
}
925+
_closeHandler();
939926
}
940-
if (_filterStatus.readPlaintextNoLongerEmpty) {
941-
_scheduleReadEvent();
927+
if (_status == closedStatus) {
928+
return;
942929
}
943-
if (_status == handshakeStatus) {
944-
await _secureHandshake();
930+
if (_filterStatus.progress) {
931+
_filterPending = true;
932+
if (_filterStatus.writeEncryptedNoLongerEmpty) {
933+
_writeSocket();
934+
}
935+
if (_filterStatus.writePlaintextNoLongerFull) {
936+
_sendWriteEvent();
937+
}
938+
if (_filterStatus.readEncryptedNoLongerFull) {
939+
_readSocket();
940+
}
941+
if (_filterStatus.readPlaintextNoLongerEmpty) {
942+
_scheduleReadEvent();
943+
}
944+
if (_status == handshakeStatus) {
945+
await _secureHandshake();
946+
}
945947
}
946948
}
947-
return _tryFilter();
948949
} catch (e, st) {
949950
_reportError(e, st);
950951
}

0 commit comments

Comments
 (0)