Skip to content

Commit ba7aaa9

Browse files
aamCommit Queue
authored andcommitted
[io/win] Ensure to check if socket is still open when requesting its type.
Fixes #61571 TEST=stdin_cancel_type_test Change-Id: I5e0a1837e72a6e41a53fc7fe163b8931082e7405 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451381 Commit-Queue: Alexander Aprelev <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent 7a372bb commit ba7aaa9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

runtime/bin/socket.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,11 @@ void FUNCTION_NAME(Socket_GetFD)(Dart_NativeArguments args) {
953953
void FUNCTION_NAME(Socket_GetType)(Dart_NativeArguments args) {
954954
Socket* socket =
955955
Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0));
956+
if (socket->fd() < 0) {
957+
OSError os_error(-1, "Socket is closed.", OSError::kUnknown);
958+
Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error));
959+
return;
960+
}
956961
OSError os_error;
957962
intptr_t type = SocketBase::GetType(socket->fd());
958963
if (type >= 0) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
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.
4+
//
5+
// Tests that asking closed stdin for its type doesn't crash.
6+
// The crash was reported on https://github.com/dart-lang/sdk/issues/61571.
7+
8+
import 'dart:io';
9+
10+
void main() async {
11+
stdin.listen((_) {}).cancel();
12+
stdin.hasTerminal;
13+
}

0 commit comments

Comments
 (0)