Skip to content

Commit be5bd1d

Browse files
committed
Rust: Also add the good example and a couple of other cited good cases to the test.
1 parent 82f2c60 commit be5bd1d

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

rust/ql/test/query-tests/security/CWE-696/BadCTorInitialization.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
| test.rs:67:4:67:9 | bad2_4 | This function has the $@ attribute but calls $@ in the standard library. | test.rs:66:1:66:7 | Attr | Attr | test.rs:69:9:69:24 | ...::stdin(...) | ...::stdin(...) |
88
| test.rs:89:4:89:9 | bad2_7 | This function has the $@ attribute but calls $@ in the standard library. | test.rs:88:1:88:7 | Attr | Attr | test.rs:90:5:90:35 | ...::sleep(...) | ...::sleep(...) |
99
| test.rs:96:4:96:9 | bad2_8 | This function has the $@ attribute but calls $@ in the standard library. | test.rs:95:1:95:7 | Attr | Attr | test.rs:97:5:97:23 | ...::exit(...) | ...::exit(...) |
10-
| test.rs:142:4:142:9 | bad4_1 | This function has the $@ attribute but calls $@ in the standard library. | test.rs:141:1:141:7 | Attr | Attr | test.rs:143:5:143:15 | ...::stdout(...) | ...::stdout(...) |
10+
| test.rs:165:4:165:9 | bad4_1 | This function has the $@ attribute but calls $@ in the standard library. | test.rs:164:1:164:7 | Attr | Attr | test.rs:166:5:166:15 | ...::stdout(...) | ...::stdout(...) |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
qltest_cargo_check: true
22
qltest_dependencies:
33
- ctor = { version = "0.2.9" }
4+
- libc-print = { version = "0.1.23" }

rust/ql/test/query-tests/security/CWE-696/test.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,29 @@ fn bad2_8() { // $ Alert[rust/ctor-initialization]
9797
process::exit(1234);
9898
}
9999

100+
#[ctor::ctor]
101+
fn harmless2_9() {
102+
libc_print::libc_println!("Hello, world!"); // does not use the std library
103+
}
104+
105+
#[ctor::ctor]
106+
fn harmless2_10() {
107+
core::assert!(true); // core library should be OK in this context
108+
}
109+
110+
extern crate alloc;
111+
use alloc::alloc::{alloc, dealloc, Layout};
112+
113+
#[ctor::ctor]
114+
unsafe fn harmless2_11() {
115+
let layout = Layout::new::<u64>();
116+
let ptr = alloc(layout); // alloc library should be OK in this context
117+
118+
if !ptr.is_null() {
119+
dealloc(ptr, layout);
120+
}
121+
}
122+
100123
// --- transitive cases ---
101124

102125
fn call_target3_1() {

0 commit comments

Comments
 (0)