Skip to content

Commit 9f83b67

Browse files
committed
Rust: Model vec::from_elem.
1 parent e2d9412 commit 9f83b67

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

rust/ql/lib/codeql/rust/frameworks/stdlib/lang-alloc.model.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ extensions:
4949
- ["<alloc::string::String as core::convert::From>::from", "Argument[0]", "ReturnValue", "value", "manual"]
5050
# Vec
5151
- ["<alloc::vec::Vec as core::convert::From>::from", "Argument[0]", "ReturnValue", "value", "manual"]
52+
- ["alloc::vec::from_elem", "Argument[0]", "ReturnValue.Element", "value", "manual"]

rust/ql/test/query-tests/security/CWE-798/HardcodedCryptographicValue.expected

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
| test_cookie.rs:17:29:17:29 | 0 | test_cookie.rs:17:29:17:29 | 0 | test_cookie.rs:18:16:18:24 | ...::from | This hard-coded value is used as $@. | test_cookie.rs:18:16:18:24 | ...::from | a key |
1616
| test_cookie.rs:21:29:21:29 | 0 | test_cookie.rs:21:29:21:29 | 0 | test_cookie.rs:22:16:22:24 | ...::from | This hard-coded value is used as $@. | test_cookie.rs:22:16:22:24 | ...::from | a key |
1717
| test_cookie.rs:38:29:38:31 | 0u8 | test_cookie.rs:38:29:38:31 | 0u8 | test_cookie.rs:42:14:42:32 | ...::from | This hard-coded value is used as $@. | test_cookie.rs:42:14:42:32 | ...::from | a key |
18+
| test_cookie.rs:49:23:49:25 | 0u8 | test_cookie.rs:49:23:49:25 | 0u8 | test_cookie.rs:53:14:53:32 | ...::from | This hard-coded value is used as $@. | test_cookie.rs:53:14:53:32 | ...::from | a key |
1819
edges
1920
| test_cipher.rs:18:9:18:14 | const1 [&ref, element] | test_cipher.rs:19:73:19:78 | const1 [&ref, element] | provenance | |
2021
| test_cipher.rs:18:28:18:36 | &... [&ref, element] | test_cipher.rs:18:9:18:14 | const1 [&ref, element] | provenance | |
@@ -76,6 +77,10 @@ edges
7677
| test_cookie.rs:38:28:38:36 | [0u8; 64] [element] | test_cookie.rs:38:18:38:37 | ...::from(...) [element] | provenance | MaD:9 |
7778
| test_cookie.rs:38:29:38:31 | 0u8 | test_cookie.rs:38:28:38:36 | [0u8; 64] [element] | provenance | |
7879
| test_cookie.rs:42:34:42:39 | array2 [element] | test_cookie.rs:42:14:42:32 | ...::from | provenance | MaD:2 Sink:MaD:2 |
80+
| test_cookie.rs:49:9:49:14 | array3 [element] | test_cookie.rs:53:34:53:39 | array3 [element] | provenance | |
81+
| test_cookie.rs:49:23:49:25 | 0u8 | test_cookie.rs:49:23:49:29 | ...::from_elem(...) [element] | provenance | MaD:11 |
82+
| test_cookie.rs:49:23:49:29 | ...::from_elem(...) [element] | test_cookie.rs:49:9:49:14 | array3 [element] | provenance | |
83+
| test_cookie.rs:53:34:53:39 | array3 [element] | test_cookie.rs:53:14:53:32 | ...::from | provenance | MaD:2 Sink:MaD:2 |
7984
models
8085
| 1 | Sink: <_ as crypto_common::KeyInit>::new_from_slice; Argument[0]; credentials-key |
8186
| 2 | Sink: <biscotti::crypto::master::Key>::from; Argument[0]; credentials-key |
@@ -87,6 +92,7 @@ models
8792
| 8 | Source: core::mem::zeroed; ReturnValue.Element; constant-source |
8893
| 9 | Summary: <alloc::vec::Vec as core::convert::From>::from; Argument[0]; ReturnValue; value |
8994
| 10 | Summary: <generic_array::GenericArray>::from_slice; Argument[0].Reference; ReturnValue.Reference; value |
95+
| 11 | Summary: alloc::vec::from_elem; Argument[0]; ReturnValue.Element; value |
9096
nodes
9197
| test_cipher.rs:18:9:18:14 | const1 [&ref, element] | semmle.label | const1 [&ref, element] |
9298
| test_cipher.rs:18:28:18:36 | &... [&ref, element] | semmle.label | &... [&ref, element] |
@@ -158,4 +164,9 @@ nodes
158164
| test_cookie.rs:38:29:38:31 | 0u8 | semmle.label | 0u8 |
159165
| test_cookie.rs:42:14:42:32 | ...::from | semmle.label | ...::from |
160166
| test_cookie.rs:42:34:42:39 | array2 [element] | semmle.label | array2 [element] |
167+
| test_cookie.rs:49:9:49:14 | array3 [element] | semmle.label | array3 [element] |
168+
| test_cookie.rs:49:23:49:25 | 0u8 | semmle.label | 0u8 |
169+
| test_cookie.rs:49:23:49:29 | ...::from_elem(...) [element] | semmle.label | ...::from_elem(...) [element] |
170+
| test_cookie.rs:53:14:53:32 | ...::from | semmle.label | ...::from |
171+
| test_cookie.rs:53:34:53:39 | array3 [element] | semmle.label | array3 [element] |
161172
subpaths

rust/ql/test/query-tests/security/CWE-798/test_cookie.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ fn test_biscotti_crypto(array_var: &[u8]) {
4646
let processor2: biscotti::Processor = config2.into();
4747

4848
let mut config3 = biscotti::ProcessorConfig::default();
49-
let array3 = vec![0u8; 64]; // $ MISSING: Alert[rust/hard-coded-cryptographic-value]
49+
let array3 = vec![0u8; 64]; // $ Alert[rust/hard-coded-cryptographic-value]
5050
let crypto_rules3 = biscotti::config::CryptoRule {
5151
cookie_names: vec!["name".to_string()],
5252
algorithm: biscotti::config::CryptoAlgorithm::Signing,
53-
key: biscotti::Key::from(array3), // $ MISSING: Sink
53+
key: biscotti::Key::from(array3), // $ Sink
5454
fallbacks: vec![],
5555
};
5656
config3.crypto_rules.push(crypto_rules3);

0 commit comments

Comments
 (0)