Skip to content

Commit c10e70a

Browse files
wip: sanitizers
1 parent c15153b commit c10e70a

File tree

16 files changed

+510
-56
lines changed

16 files changed

+510
-56
lines changed

.github/workflows/dart.yml

Lines changed: 210 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration_tests/sanitize/analysis_options.yaml

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
import "dart:ffi";
6+
7+
@Native<Pointer Function(IntPtr)>(symbol: 'malloc')
8+
external Pointer malloc(int size);
9+
@Native<Void Function(Pointer)>(symbol: 'free')
10+
external void free(Pointer ptr);
11+
@Native<Void Function(Pointer, Int, Size)>(symbol: 'memset')
12+
external void memset(Pointer ptr, int char, int size);
13+
@Native<Void Function(Pointer, Int, Size)>(symbol: 'memset', isLeaf: true)
14+
external void memset_leaf(Pointer ptr, int char, int size);
15+
@Native<Void Function(Pointer, Pointer, Size)>(symbol: 'memcmp')
16+
external void memcmp(Pointer a, Pointer b, int size);
17+
@Native<Void Function(IntPtr)>(symbol: 'usleep', isLeaf: true)
18+
external void usleep_leaf(int useconds);
19+
@Native<Void Function()>(symbol: 'abort')
20+
external void abort();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# See https://pub.dev/packages/mono_repo
2+
3+
sdk:
4+
- dev
5+
- pubspec
6+
7+
os:
8+
- linux
9+
10+
stages:
11+
- analyze_and_format:
12+
- group:
13+
- format
14+
- analyze: --fatal-infos
15+
- unit_test:
16+
- test
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: sanitize
2+
publish_to: none
3+
environment:
4+
#sdk: ^3.10.0
5+
sdk: ^3.7.0
6+
resolution: workspace
7+
dependencies:
8+
test: any
9+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
@TestOn('vm-asan')
6+
library asan_environment_test;
7+
8+
import 'package:test/test.dart';
9+
10+
void main() {
11+
test('const', () {
12+
// I.e., correct during kernel compilation.
13+
expect(const bool.fromEnvironment("dart.vm.asan"), equals(true));
14+
15+
expect(const bool.fromEnvironment("dart.vm.msan"), equals(false));
16+
expect(const bool.fromEnvironment("dart.vm.tsan"), equals(false));
17+
});
18+
19+
test('new', () {
20+
// I.e., correct during VM lookup.
21+
expect(new bool.fromEnvironment("dart.vm.asan"), equals(true));
22+
23+
expect(new bool.fromEnvironment("dart.vm.msan"), equals(false));
24+
expect(new bool.fromEnvironment("dart.vm.tsan"), equals(false));
25+
});
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
@TestOn('vm-asan')
6+
library asan_test;
7+
8+
import 'package:test/test.dart';
9+
import 'package:sanitize/libc.dart';
10+
import 'dart:ffi';
11+
12+
void main() {
13+
test('use-after-free', () {
14+
var p = malloc(sizeOf<Long>()).cast<Long>();
15+
free(p);
16+
memset(p, 42, sizeOf<Long>());
17+
});
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
@TestOn('vm && !vm-asan && !vm-msan && !vm-tsan')
6+
library environment_test;
7+
8+
import 'package:test/test.dart';
9+
10+
void main() {
11+
test('const', () {
12+
// I.e., correct during kernel compilation.
13+
expect(const bool.fromEnvironment("dart.vm.asan"), equals(false));
14+
expect(const bool.fromEnvironment("dart.vm.msan"), equals(false));
15+
expect(const bool.fromEnvironment("dart.vm.tsan"), equals(false));
16+
});
17+
18+
test('new', () {
19+
// I.e., correct during VM lookup.
20+
expect(new bool.fromEnvironment("dart.vm.asan"), equals(false));
21+
expect(new bool.fromEnvironment("dart.vm.msan"), equals(false));
22+
expect(new bool.fromEnvironment("dart.vm.tsan"), equals(false));
23+
});
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
@TestOn('vm-msan')
6+
library msan_environment_test;
7+
8+
import 'package:test/test.dart';
9+
10+
void main() {
11+
test('const', () {
12+
// I.e., correct during kernel compilation.
13+
expect(const bool.fromEnvironment("dart.vm.msan"), equals(true));
14+
15+
expect(const bool.fromEnvironment("dart.vm.asan"), equals(false));
16+
expect(const bool.fromEnvironment("dart.vm.tsan"), equals(false));
17+
});
18+
19+
test('new', () {
20+
// I.e., correct during VM lookup.
21+
expect(new bool.fromEnvironment("dart.vm.msan"), equals(true));
22+
23+
expect(new bool.fromEnvironment("dart.vm.asan"), equals(false));
24+
expect(new bool.fromEnvironment("dart.vm.tsan"), equals(false));
25+
});
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
@TestOn('vm-msan')
6+
library msan_test;
7+
8+
import 'package:sanitize/libc.dart';
9+
import 'package:test/test.dart';
10+
import 'dart:ffi';
11+
12+
void main() {
13+
test('uninitialized', () {
14+
var a = malloc(8);
15+
var b = malloc(8);
16+
memcmp(a, b, 8);
17+
free(b);
18+
free(a);
19+
});
20+
}

0 commit comments

Comments
 (0)