Skip to content

Commit c0e2f38

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[dart:io] Fix some code to be safe in the face of reflective invocation.
Reflection can invoke public members of dart:* private types when values of the private types can be returned from public members. TEST=lib/mirrors/invocation_fuzz_test CoreLibraryReviewExempt: does not change public API Bug: #31838 Bug: #46435 Bug: #51213 Change-Id: I969cd935d60455bd9cf4775b8df19838f9e6107c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428065 Reviewed-by: Brian Quinlan <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 917e519 commit c0e2f38

File tree

11 files changed

+105
-120
lines changed

11 files changed

+105
-120
lines changed

runtime/vm/service.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ char* RingServiceIdZone::GetServiceId(const Object& obj) {
431431
Thread* thread = Thread::Current();
432432
Zone* zone = thread->zone();
433433
ASSERT(zone != nullptr);
434+
if (obj.IsSmi()) {
435+
return zone->PrintToString("objects/int-%" Pd, Smi::Cast(obj).Value());
436+
}
434437
const intptr_t object_part_of_service_id = GetIdForObject(obj.ptr());
435438
return zone->PrintToString("objects/%" Pd "/%" Pd, object_part_of_service_id,
436439
id());

sdk/lib/_internal/js_dev_runtime/patch/io_patch.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class _Directory {
6969
@patch
7070
class _AsyncDirectoryListerOps {
7171
@patch
72-
factory _AsyncDirectoryListerOps(int pointer) {
72+
factory _AsyncDirectoryListerOps._(int pointer) {
7373
throw UnsupportedError("Directory._list");
7474
}
7575
}
@@ -221,7 +221,7 @@ class _Namespace {
221221
@patch
222222
class _RandomAccessFileOps {
223223
@patch
224-
factory _RandomAccessFileOps(int pointer) {
224+
factory _RandomAccessFileOps._(int pointer) {
225225
throw UnsupportedError("RandomAccessFile");
226226
}
227227
}

sdk/lib/_internal/js_runtime/lib/io_patch.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class _Directory {
6565
@patch
6666
class _AsyncDirectoryListerOps {
6767
@patch
68-
factory _AsyncDirectoryListerOps(int pointer) {
68+
factory _AsyncDirectoryListerOps._(int pointer) {
6969
throw UnsupportedError("Directory._list");
7070
}
7171
}
@@ -217,7 +217,7 @@ class _Namespace {
217217
@patch
218218
class _RandomAccessFileOps {
219219
@patch
220-
factory _RandomAccessFileOps(int pointer) {
220+
factory _RandomAccessFileOps._(int pointer) {
221221
throw UnsupportedError("RandomAccessFile");
222222
}
223223
}

sdk/lib/_internal/vm/bin/directory_patch.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,19 @@ class _Directory {
5252
@patch
5353
class _AsyncDirectoryListerOps {
5454
@patch
55-
factory _AsyncDirectoryListerOps(int pointer) =>
56-
_AsyncDirectoryListerOpsImpl(pointer);
55+
factory _AsyncDirectoryListerOps._(int pointer) =>
56+
_AsyncDirectoryListerOpsImpl._().._setPointer(pointer);
5757
}
5858

5959
base class _AsyncDirectoryListerOpsImpl extends NativeFieldWrapperClass1
6060
implements _AsyncDirectoryListerOps {
6161
_AsyncDirectoryListerOpsImpl._();
6262

63-
factory _AsyncDirectoryListerOpsImpl(int pointer) =>
64-
_AsyncDirectoryListerOpsImpl._().._setPointer(pointer);
65-
6663
@pragma("vm:external-name", "Directory_SetAsyncDirectoryListerPointer")
6764
external void _setPointer(int pointer);
6865

6966
@pragma("vm:external-name", "Directory_GetAsyncDirectoryListerPointer")
70-
external int getPointer();
67+
external int _getPointer();
7168
}
7269

7370
// Corelib 'Uri.base' implementation.

sdk/lib/_internal/vm/bin/file_patch.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,19 @@ class _File {
9090
@patch
9191
class _RandomAccessFileOps {
9292
@patch
93-
factory _RandomAccessFileOps(int pointer) =>
94-
_RandomAccessFileOpsImpl(pointer);
93+
factory _RandomAccessFileOps._(int pointer) =>
94+
_RandomAccessFileOpsImpl._().._setPointer(pointer);
9595
}
9696

9797
@pragma("vm:entry-point")
9898
base class _RandomAccessFileOpsImpl extends NativeFieldWrapperClass1
9999
implements _RandomAccessFileOps {
100100
_RandomAccessFileOpsImpl._();
101101

102-
factory _RandomAccessFileOpsImpl(int pointer) =>
103-
_RandomAccessFileOpsImpl._().._setPointer(pointer);
104-
105102
@pragma("vm:external-name", "File_SetPointer")
106103
external void _setPointer(int pointer);
107104
@pragma("vm:external-name", "File_GetPointer")
108-
external int getPointer();
105+
external int _getPointer();
109106
@pragma("vm:external-name", "File_GetFD")
110107
external int get fd;
111108
@pragma("vm:external-name", "File_Close")

0 commit comments

Comments
 (0)