Skip to content

Commit 8e8374b

Browse files
committed
Rust: Label source annotations in the test properly.
1 parent da4fbfb commit 8e8374b

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed
Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +0,0 @@
1-
#select
2-
testFailures
3-
| deallocation.rs:20:36:20:54 | //... | Missing result: Source=dealloc |
4-
| deallocation.rs:70:47:70:71 | //... | Missing result: Source=dealloc_array |
5-
| deallocation.rs:112:44:112:59 | //... | Missing result: Source=free |
6-
| deallocation.rs:123:45:123:64 | //... | Missing result: Source=dangling |
7-
| deallocation.rs:124:47:124:70 | //... | Missing result: Source=dangling_mut |
8-
| deallocation.rs:125:41:125:56 | //... | Missing result: Source=null |
9-
| deallocation.rs:176:32:176:56 | //... | Missing result: Source=drop_in_place |
10-
| deallocation.rs:242:33:242:57 | //... | Missing result: Source=drop_in_place |

rust/ql/test/query-tests/security/CWE-825/deallocation.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn test_alloc(mode: i32) {
1717
println!(" v3 = {v3}");
1818
println!(" v4 = {v4}");
1919

20-
std::alloc::dealloc(m1, layout); // $ Source=dealloc
20+
std::alloc::dealloc(m1, layout); // $ Source[rust/access-invalid-pointer]=dealloc
2121
// (m1, m2 are now dangling)
2222

2323
match mode {
@@ -67,7 +67,7 @@ pub fn test_alloc_array(mode: i32) {
6767
println!(" v1 = {v1}");
6868
println!(" v2 = {v2}");
6969

70-
std::alloc::dealloc(m2 as *mut u8, layout); // $ Source=dealloc_array
70+
std::alloc::dealloc(m2 as *mut u8, layout); // $ Source[rust/access-invalid-pointer]=dealloc_array
7171
// m1, m2 are now dangling
7272

7373
match mode {
@@ -109,7 +109,7 @@ pub fn test_libc() {
109109
let v1 = *my_ptr; // GOOD
110110
println!(" v1 = {v1}");
111111

112-
libc::free(my_ptr as *mut libc::c_void); // $ Source=free
112+
libc::free(my_ptr as *mut libc::c_void); // $ Source[rust/access-invalid-pointer]=free
113113
// (my_ptr is now dangling)
114114

115115
let v2 = *my_ptr; // $ Alert[rust/access-invalid-pointer]=free
@@ -120,9 +120,9 @@ pub fn test_libc() {
120120
// --- std::ptr ---
121121

122122
pub fn test_ptr_invalid(mode: i32) {
123-
let p1: *const i64 = std::ptr::dangling(); // $ Source=dangling
124-
let p2: *mut i64 = std::ptr::dangling_mut(); // $ Source=dangling_mut
125-
let p3: *const i64 = std::ptr::null(); // $ Source=null
123+
let p1: *const i64 = std::ptr::dangling(); // $ Source[rust/access-invalid-pointer]=dangling
124+
let p2: *mut i64 = std::ptr::dangling_mut(); // $ Source[rust/access-invalid-pointer]=dangling_mut
125+
let p3: *const i64 = std::ptr::null(); // $ Source[rust/access-invalid-pointer]=null
126126

127127
if mode == 120 {
128128
unsafe {
@@ -173,7 +173,7 @@ pub fn test_ptr_drop(mode: i32) {
173173
println!(" v1 = {v1}");
174174
println!(" v2 = {v2}");
175175

176-
std::ptr::drop_in_place(p1); // $ Source=drop_in_place
176+
std::ptr::drop_in_place(p1); // $ Source[rust/access-invalid-pointer]=drop_in_place
177177
// explicitly destructs the pointed-to `m2`
178178

179179
if mode == 1 {
@@ -212,7 +212,7 @@ impl Drop for MyDropBuffer {
212212

213213
unsafe {
214214
_ = *self.ptr;
215-
drop(*self.ptr); // $ MISSING: Source=drop
215+
drop(*self.ptr); // $ MISSING: Source[rust/access-invalid-pointer]=drop
216216
_ = *self.ptr; // $ MISSING: Alert[rust/access-invalid-pointer]=drop
217217
std::alloc::dealloc(self.ptr, layout);
218218
}
@@ -239,7 +239,7 @@ fn test_qhelp_example_good(ptr: *mut String) {
239239

240240
fn test_qhelp_example_bad(ptr: *mut String) {
241241
unsafe {
242-
std::ptr::drop_in_place(ptr); // $ Source=drop_in_place
242+
std::ptr::drop_in_place(ptr); // $ Source[rust/access-invalid-pointer]=drop_in_place
243243
}
244244

245245
// ...
@@ -280,7 +280,7 @@ pub fn test_vec_reserve() {
280280
println!(" v1 = {}", v1);
281281
}
282282

283-
vec1.reserve(1000); // $ MISSING: Source=reserve
283+
vec1.reserve(1000); // $ MISSING: Source[rust/access-invalid-pointer]=reserve
284284
// (may invalidate the pointer)
285285

286286
unsafe {
@@ -300,7 +300,7 @@ pub fn test_vec_reserve() {
300300
}
301301

302302
for _i in 0..1000 {
303-
vec2.push(0); // $ MISSING: Source=push
303+
vec2.push(0); // $ MISSING: Source[rust/access-invalid-pointer]=push
304304
// (may invalidate the pointer)
305305
}
306306

0 commit comments

Comments
 (0)