Skip to content

Commit d1a0237

Browse files
committed
Rust: Correct a few details in the test.
1 parent c84e2cd commit d1a0237

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

rust/ql/test/query-tests/security/CWE-825/AccessInvalidPointer.expected

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
| deallocation.rs:131:14:131:15 | p2 | deallocation.rs:124:21:124:42 | ...::dangling_mut | deallocation.rs:131:14:131:15 | p2 | This operation dereferences a pointer that may be $@. | deallocation.rs:124:21:124:42 | ...::dangling_mut | invalid |
1414
| deallocation.rs:132:14:132:15 | p3 | deallocation.rs:125:23:125:36 | ...::null | deallocation.rs:132:14:132:15 | p3 | This operation dereferences a pointer that may be $@. | deallocation.rs:125:23:125:36 | ...::null | invalid |
1515
| deallocation.rs:180:15:180:16 | p1 | deallocation.rs:176:3:176:25 | ...::drop_in_place | deallocation.rs:180:15:180:16 | p1 | This operation dereferences a pointer that may be $@. | deallocation.rs:176:3:176:25 | ...::drop_in_place | invalid |
16-
| deallocation.rs:214:18:214:20 | ptr | deallocation.rs:208:3:208:25 | ...::drop_in_place | deallocation.rs:214:18:214:20 | ptr | This operation dereferences a pointer that may be $@. | deallocation.rs:208:3:208:25 | ...::drop_in_place | invalid |
16+
| deallocation.rs:216:18:216:20 | ptr | deallocation.rs:210:3:210:25 | ...::drop_in_place | deallocation.rs:216:18:216:20 | ptr | This operation dereferences a pointer that may be $@. | deallocation.rs:210:3:210:25 | ...::drop_in_place | invalid |
1717
edges
1818
| deallocation.rs:20:3:20:21 | ...::dealloc | deallocation.rs:20:23:20:24 | [post] m1 | provenance | Src:MaD:3 MaD:3 |
1919
| deallocation.rs:20:23:20:24 | [post] m1 | deallocation.rs:26:15:26:16 | m1 | provenance | |
@@ -40,8 +40,8 @@ edges
4040
| deallocation.rs:125:23:125:38 | ...::null(...) | deallocation.rs:125:6:125:7 | p3 | provenance | |
4141
| deallocation.rs:176:3:176:25 | ...::drop_in_place | deallocation.rs:176:27:176:28 | [post] p1 | provenance | Src:MaD:6 MaD:6 |
4242
| deallocation.rs:176:27:176:28 | [post] p1 | deallocation.rs:180:15:180:16 | p1 | provenance | |
43-
| deallocation.rs:208:3:208:25 | ...::drop_in_place | deallocation.rs:208:27:208:29 | [post] ptr | provenance | Src:MaD:6 MaD:6 |
44-
| deallocation.rs:208:27:208:29 | [post] ptr | deallocation.rs:214:18:214:20 | ptr | provenance | |
43+
| deallocation.rs:210:3:210:25 | ...::drop_in_place | deallocation.rs:210:27:210:29 | [post] ptr | provenance | Src:MaD:6 MaD:6 |
44+
| deallocation.rs:210:27:210:29 | [post] ptr | deallocation.rs:216:18:216:20 | ptr | provenance | |
4545
models
4646
| 1 | Sink: lang:core; crate::ptr::read; pointer-access; Argument[0] |
4747
| 2 | Sink: lang:core; crate::ptr::write; pointer-access; Argument[0] |
@@ -83,7 +83,7 @@ nodes
8383
| deallocation.rs:176:3:176:25 | ...::drop_in_place | semmle.label | ...::drop_in_place |
8484
| deallocation.rs:176:27:176:28 | [post] p1 | semmle.label | [post] p1 |
8585
| deallocation.rs:180:15:180:16 | p1 | semmle.label | p1 |
86-
| deallocation.rs:208:3:208:25 | ...::drop_in_place | semmle.label | ...::drop_in_place |
87-
| deallocation.rs:208:27:208:29 | [post] ptr | semmle.label | [post] ptr |
88-
| deallocation.rs:214:18:214:20 | ptr | semmle.label | ptr |
86+
| deallocation.rs:210:3:210:25 | ...::drop_in_place | semmle.label | ...::drop_in_place |
87+
| deallocation.rs:210:27:210:29 | [post] ptr | semmle.label | [post] ptr |
88+
| deallocation.rs:216:18:216:20 | ptr | semmle.label | ptr |
8989
subpaths

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,13 @@ pub fn test_ptr_drop(mode: i32) {
187187
}
188188
}
189189

190+
// --- qhelp examples ---
191+
190192
fn do_something(s: &String) {
191193
println!(" s = {}", s);
192194
}
193195

194-
fn test_qhelp_test_good(ptr: *mut String) {
196+
fn test_qhelp_example_good(ptr: *mut String) {
195197
unsafe {
196198
do_something(&*ptr);
197199
}
@@ -203,7 +205,7 @@ fn test_qhelp_test_good(ptr: *mut String) {
203205
}
204206
}
205207

206-
fn test_qhelp_test_bad(ptr: *mut String) {
208+
fn test_qhelp_example_bad(ptr: *mut String) {
207209
unsafe {
208210
std::ptr::drop_in_place(ptr); // $ Source=drop_in_place
209211
}
@@ -215,7 +217,7 @@ fn test_qhelp_test_bad(ptr: *mut String) {
215217
}
216218
}
217219

218-
pub fn test_qhelp_tests() {
220+
pub fn test_qhelp_examples() {
219221
let layout = std::alloc::Layout::new::<[String; 2]>();
220222
unsafe {
221223
let ptr = std::alloc::alloc(layout);
@@ -226,14 +228,16 @@ pub fn test_qhelp_tests() {
226228
*ptr1 = String::from("123");
227229
*ptr2 = String::from("456");
228230

229-
test_qhelp_test_good(ptr1);
231+
test_qhelp_example_good(ptr1);
230232

231-
test_qhelp_test_bad(ptr2);
233+
test_qhelp_example_bad(ptr2);
232234

233235
std::alloc::dealloc(ptr, layout);
234236
}
235237
}
236238

239+
// --- Vec ---
240+
237241
pub fn test_vec_reserve() {
238242
let mut vec1 = Vec::<u16>::new();
239243
vec1.push(100);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn main() {
129129
test_ptr_drop(mode);
130130

131131
println!("test_qhelp_tests:");
132-
test_qhelp_tests();
132+
test_qhelp_examples();
133133

134134
println!("test_vec_reserve:");
135135
test_vec_reserve();

0 commit comments

Comments
 (0)