Skip to content

Commit 284a7ee

Browse files
a-sivaCommit Queue
authored andcommitted
[VM/IO] Fix error path in SocketAddress::GetSockAddr
Dart_TypedDataReleaseData was not called in an error path. Should fix #60421 TEST=tests/standalone/io/datagram_error_test.dart Change-Id: I1935af1c5beed9d696a0543d0e97f2d549743879 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418701 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Siva Annamalai <[email protected]>
1 parent b0c3f4e commit 284a7ee

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

runtime/bin/socket_base.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ void SocketAddress::GetSockAddr(Dart_Handle obj, RawAddr* addr) {
113113
}
114114
if ((data_type != Dart_TypedData_kUint8) ||
115115
((len != sizeof(in_addr)) && (len != sizeof(in6_addr)))) {
116+
Dart_TypedDataReleaseData(obj);
116117
Dart_PropagateError(Dart_NewApiError("Unexpected type for socket address"));
117118
}
118119
memset(reinterpret_cast<void*>(addr), 0, sizeof(RawAddr));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
// Dart test program for testing error path in datagram bind call.
6+
7+
import 'dart:io';
8+
9+
import "package:expect/expect.dart";
10+
11+
void main() async {
12+
try {
13+
final socket = await RawDatagramSocket.bind(
14+
InternetAddress('/tmp/test_socket', type: InternetAddressType.unix),
15+
0,
16+
);
17+
Expect.fail(
18+
"Should not reach this: "
19+
"the bind call above should have failed",
20+
);
21+
socket.listen((data) {
22+
print(data);
23+
});
24+
} catch (e) {
25+
Expect.fail(
26+
"Should not reach this: "
27+
"the bind call above throws unhandled exception",
28+
);
29+
}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// Dart test program for testing error path in datagram bind call.
6+
//
7+
// OtherResources=datagram_error.dart
8+
9+
import 'dart:io';
10+
11+
import "package:expect/expect.dart";
12+
import 'package:path/path.dart' as path;
13+
14+
void main() async {
15+
var sdkPath = path.absolute(path.dirname(Platform.executable));
16+
var dartPath = path.absolute(
17+
sdkPath,
18+
Platform.isWindows ? 'dart.exe' : 'dart',
19+
);
20+
// Get the Dart script file that generates output.
21+
var scriptFile = new File(
22+
Platform.script.resolve("datagram_error.dart").toFilePath(),
23+
);
24+
var args = <String>[scriptFile.path];
25+
ProcessResult syncResult = Process.runSync(dartPath, args);
26+
Expect.notEquals(0, syncResult.exitCode);
27+
Expect.stringEquals(
28+
syncResult.stderr,
29+
"Unexpected type for socket address" + Platform.lineTerminator,
30+
);
31+
}

0 commit comments

Comments
 (0)