[vm/io] Null-terminate scope-copied CStrings.

Fixes https://github.com/dart-lang/sdk/issues/54741
TEST=standalone/io/io_override_test

Change-Id: Ie907360dc4bcea05ef6fe3a5d4626e4e31399fc6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348723
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Alexander Aprelev 2024-01-26 22:08:37 +00:00 committed by Commit Queue
parent 55310a1c70
commit 1d1531c8d9
2 changed files with 13 additions and 1 deletions

View file

@ -56,8 +56,9 @@ intptr_t TypedDataScope::size_in_bytes() const {
}
const char* TypedDataScope::GetScopedCString() const {
char* buf = reinterpret_cast<char*>(Dart_ScopeAllocate(size_in_bytes()));
char* buf = reinterpret_cast<char*>(Dart_ScopeAllocate(size_in_bytes() + 1));
strncpy(buf, GetCString(), size_in_bytes());
buf[size_in_bytes()] = '\0';
return buf;
}

View file

@ -293,8 +293,19 @@ globalIOOverridesZoneTest() {
Expect.isTrue(dir is Directory);
}
class EmptyOverride extends IOOverrides {}
void emptyIOOverride() {
IOOverrides.runWithIOOverrides(
() => Expect.equals(
FileSystemEntity.typeSync('/'), FileSystemEntityType.directory),
EmptyOverride(),
);
}
main() async {
await ioOverridesRunTest();
globalIOOverridesTest();
globalIOOverridesZoneTest();
emptyIOOverride();
}