Skip to content

Commit 018c534

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm] Handle short writes in Builtin_PrintString.
Also avoid polluting the repository working directory when fuzzing. TEST=lib/mirrors/invocation_fuzz_test Bug: #60721 Change-Id: Ibe2f2d35479bbf969cff74c954acd606c1fc0679 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428381 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Alexander Aprelev <[email protected]>
1 parent 00fbc2c commit 018c534

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

runtime/bin/builtin_natives.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,14 @@ void FUNCTION_NAME(Builtin_PrintString)(Dart_NativeArguments args) {
9999
chars[length] = '\n';
100100

101101
// Uses fwrite to support printing NUL bytes.
102-
intptr_t res = fwrite(chars, 1, new_length, stdout);
103-
ASSERT(res == new_length);
102+
const uint8_t* cursor = chars;
103+
intptr_t remaining = new_length;
104+
while (remaining > 0) {
105+
intptr_t written = fwrite(cursor, 1, remaining, stdout);
106+
if (written == 0) break; // EOF or error: ignore
107+
cursor += written;
108+
remaining -= written;
109+
}
104110
fflush(stdout);
105111
if (ShouldCaptureStdout()) {
106112
// For now we report print output on the Stdout stream.

tests/lib/mirrors/invocation_fuzz_test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,17 @@ doOneTask() {
162162
var fuzzArgument;
163163

164164
main() {
165+
// Avoid polluting the repository. Use a fixed path instead dynamically
166+
// creating one because this test won't reliably cleanup on exit and we'd
167+
// like to avoid accumulating temp directories.
168+
var d = Directory(Directory.systemTemp.path + "/invocation_fuzz_test");
169+
d.createSync();
170+
Directory.current = d;
171+
165172
fuzzArgument = null;
166173
fuzzArgument = 1; // //# smi: ok
167174
fuzzArgument = false; // //# false: ok
168-
fuzzArgument = 'string'; // //# string: ok
175+
fuzzArgument = 'fuzzstring'; // //# string: ok
169176
fuzzArgument = new List.filled(0, null); // //# emptyarray: ok
170177

171178
print('Fuzzing with $fuzzArgument');

0 commit comments

Comments
 (0)