Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions rust/extractor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,12 @@ fn main() -> anyhow::Result<()> {
}
// Fast path when there is no ambiguity in dependency extraction.
if dependency_extraction_ambiguity {
for (_, file) in dependency_files(&db, &vfs, &source_files) {
extractor.extract_with_semantics(file, &semantics, &vfs, library_mode);
for (file_id, file) in dependency_files(&db, &vfs, &source_files) {
// Dependency files outside any crate's module tree (e.g.
// tests, examples or cfg-disabled modules) are skipped.
if semantics.file_to_module_def(file_id).is_some() {
extractor.extract_with_semantics(file, &semantics, &vfs, library_mode);
}
}
} else {
dependencies.add_manifest(manifest, &semantics, &vfs, &source_files);
Expand Down Expand Up @@ -366,13 +370,15 @@ fn main() -> anyhow::Result<()> {
// the case `file_to_module_def` will return `None` for the
// file. When this is the case and there are alternatives we
// do not extract the file yet. Instead the file will be
// considered again in the next iteration of the loop.
if !dependencies.has_alternative(&file)
|| path_to_file_id(&file, &vfs)
.and_then(|id| semantics.file_to_module_def(id))
.is_some()
{
// considered again in the next iteration of the loop. If
// no configuration includes the file, it is not extracted.
let in_module = path_to_file_id(&file, &vfs)
.and_then(|id| semantics.file_to_module_def(id))
.is_some();
if in_module {
extractor.extract_with_semantics(&file, &semantics, &vfs, library_mode);
}
if in_module || !dependencies.has_alternative(&file) {
dependencies.extracted(&file);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Not part of alpha's module tree, so it must not be extracted.
pub fn orphan() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import rust

from Function f
where f.getFile().getBaseName() = "only_a.rs"
where f.getFile().getBaseName() = ["only_a.rs", "orphan.rs"]
select f, f.getName()
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def test_dependency_features(codeql, rust, cwd, configurations, reverse):
|-- dependencies/
| |-- alpha/
| | |-- Cargo.toml
| | `-- src/lib.rs # feature-gated functions and invoke! macro
| | `-- src/
| | |-- lib.rs # feature-gated functions and invoke! macro
| | |-- only_a.rs # feature-gated module
| | `-- orphan.rs # not in the module tree
| `-- beta/
| |-- Cargo.toml
| `-- src/lib.rs # feature-gated functions and invoke! macro
Expand All @@ -55,7 +58,8 @@ def test_dependency_features(codeql, rust, cwd, configurations, reverse):

Alpha's `only_a` module is disabled by feature `b`. Its item macro must still
be expanded using a configuration in which the module is enabled, even when
a richer configuration wins for alpha's other files.
a richer configuration wins for alpha's other files. Alpha's `orphan.rs` is
not in the module tree of any configuration, so it must not be extracted.
"""
if reverse:
configurations = configurations[::-1]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The Rust extractor no longer extracts dependency files that are not part of any crate's module tree (for example tests, examples, or modules disabled for the current target). This makes extraction faster and the resulting databases smaller.
Original file line number Diff line number Diff line change
Expand Up @@ -38,52 +38,52 @@ edges
| test_cipher.rs:18:28:18:36 | &... [&ref] | test_cipher.rs:18:9:18:14 | const1 [&ref] | provenance | |
| test_cipher.rs:18:29:18:36 | [0u8; 16] | test_cipher.rs:18:28:18:36 | &... [&ref] | provenance | |
| test_cipher.rs:19:49:19:79 | ...::from_slice(...) [&ref] | test_cipher.rs:19:49:19:79 | ...::from_slice(...) | provenance | Sink:MaD:3 |
| test_cipher.rs:19:73:19:78 | const1 [&ref] | test_cipher.rs:19:49:19:79 | ...::from_slice(...) [&ref] | provenance | MaD:22 |
| test_cipher.rs:19:73:19:78 | const1 [&ref] | test_cipher.rs:19:49:19:79 | ...::from_slice(...) [&ref] | provenance | MaD:21 |
| test_cipher.rs:25:9:25:14 | const4 [&ref] | test_cipher.rs:26:66:26:71 | const4 [&ref] | provenance | |
| test_cipher.rs:25:28:25:36 | &... [&ref] | test_cipher.rs:25:9:25:14 | const4 [&ref] | provenance | |
| test_cipher.rs:25:29:25:36 | [0u8; 16] | test_cipher.rs:25:28:25:36 | &... [&ref] | provenance | |
| test_cipher.rs:26:42:26:72 | ...::from_slice(...) [&ref] | test_cipher.rs:26:42:26:72 | ...::from_slice(...) | provenance | Sink:MaD:4 |
| test_cipher.rs:26:66:26:71 | const4 [&ref] | test_cipher.rs:26:42:26:72 | ...::from_slice(...) [&ref] | provenance | MaD:22 |
| test_cipher.rs:26:66:26:71 | const4 [&ref] | test_cipher.rs:26:42:26:72 | ...::from_slice(...) [&ref] | provenance | MaD:21 |
| test_cipher.rs:29:9:29:14 | const5 [&ref] | test_cipher.rs:30:95:30:100 | const5 [&ref] | provenance | |
| test_cipher.rs:29:28:29:36 | &... [&ref] | test_cipher.rs:29:9:29:14 | const5 [&ref] | provenance | |
| test_cipher.rs:29:29:29:36 | [0u8; 16] | test_cipher.rs:29:28:29:36 | &... [&ref] | provenance | |
| test_cipher.rs:30:72:30:101 | ...::from_slice(...) [&ref] | test_cipher.rs:30:72:30:101 | ...::from_slice(...) | provenance | Sink:MaD:5 |
| test_cipher.rs:30:95:30:100 | const5 [&ref] | test_cipher.rs:30:72:30:101 | ...::from_slice(...) [&ref] | provenance | MaD:22 |
| test_cipher.rs:30:95:30:100 | const5 [&ref] | test_cipher.rs:30:72:30:101 | ...::from_slice(...) [&ref] | provenance | MaD:21 |
| test_cipher.rs:37:9:37:14 | const7 | test_cipher.rs:38:74:38:79 | const7 | provenance | |
| test_cipher.rs:37:27:37:74 | [...] | test_cipher.rs:37:9:37:14 | const7 | provenance | |
| test_cipher.rs:38:49:38:80 | ...::from_slice(...) [&ref] | test_cipher.rs:38:49:38:80 | ...::from_slice(...) | provenance | Sink:MaD:3 |
| test_cipher.rs:38:73:38:79 | &const7 [&ref] | test_cipher.rs:38:49:38:80 | ...::from_slice(...) [&ref] | provenance | MaD:22 |
| test_cipher.rs:38:73:38:79 | &const7 [&ref] | test_cipher.rs:38:49:38:80 | ...::from_slice(...) [&ref] | provenance | MaD:21 |
| test_cipher.rs:38:74:38:79 | const7 | test_cipher.rs:38:73:38:79 | &const7 [&ref] | provenance | |
| test_cipher.rs:41:9:41:14 | const8 [&ref] | test_cipher.rs:42:73:42:78 | const8 [&ref] | provenance | |
| test_cipher.rs:41:28:41:76 | &... [&ref] | test_cipher.rs:41:9:41:14 | const8 [&ref] | provenance | |
| test_cipher.rs:41:29:41:76 | [...] | test_cipher.rs:41:28:41:76 | &... [&ref] | provenance | |
| test_cipher.rs:42:49:42:79 | ...::from_slice(...) [&ref] | test_cipher.rs:42:49:42:79 | ...::from_slice(...) | provenance | Sink:MaD:3 |
| test_cipher.rs:42:73:42:78 | const8 [&ref] | test_cipher.rs:42:49:42:79 | ...::from_slice(...) [&ref] | provenance | MaD:22 |
| test_cipher.rs:42:73:42:78 | const8 [&ref] | test_cipher.rs:42:49:42:79 | ...::from_slice(...) [&ref] | provenance | MaD:21 |
| test_cipher.rs:50:9:50:15 | const10 [element] | test_cipher.rs:51:75:51:81 | const10 [element] | provenance | |
| test_cipher.rs:50:37:50:54 | ...::zeroed(...) | test_cipher.rs:50:9:50:15 | const10 [element] | provenance | Src:MaD:11 |
| test_cipher.rs:51:50:51:82 | ...::from_slice(...) [&ref, element] | test_cipher.rs:51:50:51:82 | ...::from_slice(...) | provenance | Sink:MaD:3 Sink:MaD:3 |
| test_cipher.rs:51:74:51:81 | &const10 [&ref, element] | test_cipher.rs:51:50:51:82 | ...::from_slice(...) [&ref, element] | provenance | MaD:22 |
| test_cipher.rs:51:74:51:81 | &const10 [&ref, element] | test_cipher.rs:51:50:51:82 | ...::from_slice(...) [&ref, element] | provenance | MaD:21 |
| test_cipher.rs:51:75:51:81 | const10 [element] | test_cipher.rs:51:74:51:81 | &const10 [&ref, element] | provenance | |
| test_cipher.rs:66:9:66:14 | const2 [&ref] | test_cipher.rs:67:35:67:40 | const2 [&ref] | provenance | |
| test_cipher.rs:66:18:66:26 | &... [&ref] | test_cipher.rs:66:9:66:14 | const2 [&ref] | provenance | |
| test_cipher.rs:66:19:66:26 | [0u8; 32] | test_cipher.rs:66:18:66:26 | &... [&ref] | provenance | |
| test_cipher.rs:67:35:67:40 | const2 [&ref] | test_cipher.rs:67:35:67:47 | const2.into() [element] | provenance | MaD:20 |
| test_cipher.rs:67:35:67:40 | const2 [&ref] | test_cipher.rs:67:35:67:47 | const2.into() [element] | provenance | MaD:13 |
| test_cipher.rs:67:35:67:47 | const2.into() [element] | test_cipher.rs:67:35:67:47 | const2.into() | provenance | Sink:MaD:7 |
| test_cipher.rs:73:9:73:14 | const2 [&ref] | test_cipher.rs:74:46:74:51 | const2 | provenance | Sink:MaD:8 |
| test_cipher.rs:73:18:73:26 | &... [&ref] | test_cipher.rs:73:9:73:14 | const2 [&ref] | provenance | |
| test_cipher.rs:73:19:73:26 | [0u8; 32] | test_cipher.rs:73:18:73:26 | &... [&ref] | provenance | |
| test_cipher.rs:80:9:80:14 | const6 [&ref] | test_cipher.rs:81:63:81:68 | const6 [&ref] | provenance | |
| test_cipher.rs:80:18:80:26 | &... [&ref] | test_cipher.rs:80:9:80:14 | const6 [&ref] | provenance | |
| test_cipher.rs:80:19:80:26 | [0u8; 32] | test_cipher.rs:80:18:80:26 | &... [&ref] | provenance | |
| test_cipher.rs:81:63:81:68 | const6 [&ref] | test_cipher.rs:81:63:81:75 | const6.into() [element] | provenance | MaD:20 |
| test_cipher.rs:81:63:81:68 | const6 [&ref] | test_cipher.rs:81:63:81:75 | const6.into() [element] | provenance | MaD:13 |
| test_cipher.rs:81:63:81:75 | const6.into() [element] | test_cipher.rs:81:63:81:75 | const6.into() | provenance | Sink:MaD:9 |
| test_cipher.rs:84:9:84:14 | const7 [&ref] | test_cipher.rs:85:75:85:80 | const7 [&ref] | provenance | |
| test_cipher.rs:84:18:84:27 | &... [&ref] | test_cipher.rs:84:9:84:14 | const7 [&ref] | provenance | |
| test_cipher.rs:84:19:84:27 | [0u8; 16] | test_cipher.rs:84:18:84:27 | &... [&ref] | provenance | |
| test_cipher.rs:85:75:85:80 | const7 [&ref] | test_cipher.rs:85:75:85:87 | const7.into() [element] | provenance | MaD:20 |
| test_cipher.rs:85:75:85:80 | const7 [&ref] | test_cipher.rs:85:75:85:87 | const7.into() [element] | provenance | MaD:13 |
| test_cipher.rs:85:75:85:87 | const7.into() [element] | test_cipher.rs:85:75:85:87 | const7.into() | provenance | Sink:MaD:10 |
| test_cipher.rs:94:9:94:12 | key9 [&ref] | test_cipher.rs:95:63:95:66 | key9 [&ref] | provenance | |
| test_cipher.rs:94:23:94:40 | "1234567890123456" | test_cipher.rs:94:23:94:51 | "1234567890123456".as_bytes() [&ref] | provenance | MaD:21 |
| test_cipher.rs:94:23:94:40 | "1234567890123456" | test_cipher.rs:94:23:94:51 | "1234567890123456".as_bytes() [&ref] | provenance | MaD:20 |
| test_cipher.rs:94:23:94:51 | "1234567890123456".as_bytes() [&ref] | test_cipher.rs:94:9:94:12 | key9 [&ref] | provenance | |
| test_cipher.rs:95:63:95:66 | key9 [&ref] | test_cipher.rs:95:63:95:73 | key9.into() [element] | provenance | MaD:13 |
| test_cipher.rs:95:63:95:73 | key9.into() [element] | test_cipher.rs:95:63:95:73 | key9.into() | provenance | Sink:MaD:9 |
Expand All @@ -110,7 +110,7 @@ edges
| test_cipher.rs:129:33:129:41 | [0xff; 32] | test_cipher.rs:129:32:129:41 | &... [&ref] | provenance | |
| test_cipher.rs:130:9:130:12 | key3 [&ref] | test_cipher.rs:132:35:132:38 | key3 [&ref] | provenance | |
| test_cipher.rs:130:16:130:55 | ...::from_slice(...) [&ref] | test_cipher.rs:130:9:130:12 | key3 [&ref] | provenance | |
| test_cipher.rs:130:45:130:54 | key3_array [&ref] | test_cipher.rs:130:16:130:55 | ...::from_slice(...) [&ref] | provenance | MaD:22 |
| test_cipher.rs:130:45:130:54 | key3_array [&ref] | test_cipher.rs:130:16:130:55 | ...::from_slice(...) [&ref] | provenance | MaD:21 |
| test_cipher.rs:131:9:131:14 | nonce3 | test_cipher.rs:133:30:133:35 | nonce3 | provenance | |
| test_cipher.rs:131:27:131:35 | [0xff; 12] | test_cipher.rs:131:9:131:14 | nonce3 | provenance | |
| test_cipher.rs:132:34:132:38 | &key3 [&ref, &ref] | test_cipher.rs:132:34:132:38 | &key3 | provenance | Sink:MaD:7 Sink:MaD:7 |
Expand All @@ -132,7 +132,7 @@ edges
| test_cookie.rs:22:27:22:32 | array2 | test_cookie.rs:22:26:22:32 | &array2 [&ref] | provenance | |
| test_cookie.rs:25:9:25:12 | str3 | test_cookie.rs:30:26:30:29 | str3 | provenance | |
| test_cookie.rs:25:16:29:5 | match val { ... } | test_cookie.rs:25:9:25:12 | str3 | provenance | |
| test_cookie.rs:30:26:30:29 | str3 | test_cookie.rs:30:26:30:40 | str3.as_bytes() [&ref] | provenance | MaD:21 |
| test_cookie.rs:30:26:30:29 | str3 | test_cookie.rs:30:26:30:40 | str3.as_bytes() [&ref] | provenance | MaD:20 |
| test_cookie.rs:30:26:30:40 | str3.as_bytes() [&ref] | test_cookie.rs:30:26:30:40 | str3.as_bytes() | provenance | Sink:MaD:6 |
| test_cookie.rs:33:9:33:14 | array4 | test_cookie.rs:38:27:38:32 | array4 | provenance | |
| test_cookie.rs:33:27:37:5 | [...] | test_cookie.rs:33:9:33:14 | array4 | provenance | |
Expand All @@ -146,7 +146,7 @@ edges
| test_cookie.rs:54:28:54:36 | [0u8; 64] | test_cookie.rs:54:18:54:37 | ...::from(...) | provenance | MaD:18 |
| test_cookie.rs:54:28:54:36 | [0u8; 64] | test_cookie.rs:54:18:54:37 | ...::from(...) | provenance | MaD:19 |
| test_cookie.rs:65:9:65:14 | array3 [element] | test_cookie.rs:69:34:69:39 | array3 | provenance | Sink:MaD:2 |
| test_cookie.rs:65:23:65:25 | 0u8 | test_cookie.rs:65:23:65:29 | ...::from_elem(...) [element] | provenance | MaD:23 |
| test_cookie.rs:65:23:65:25 | 0u8 | test_cookie.rs:65:23:65:29 | ...::from_elem(...) [element] | provenance | MaD:22 |
| test_cookie.rs:65:23:65:29 | ...::from_elem(...) [element] | test_cookie.rs:65:9:65:14 | array3 [element] | provenance | |
| test_heuristic.rs:38:25:38:30 | 0xFFFF | test_heuristic.rs:81:22:81:31 | MY_CONST_1 | provenance | |
| test_heuristic.rs:39:25:39:59 | ... as u64 | test_heuristic.rs:82:22:82:31 | MY_CONST_2 | provenance | |
Expand Down Expand Up @@ -179,10 +179,9 @@ models
| 17 | Summary: <alloc::vec::Vec as core::convert::From>::from; Argument[0].Field[alloc::bstr::ByteString(0)]; ReturnValue; value |
| 18 | Summary: <alloc::vec::Vec as core::convert::From>::from; Argument[0].Field[alloc::collections::binary_heap::BinaryHeap::data]; ReturnValue; value |
| 19 | Summary: <alloc::vec::Vec as core::convert::From>::from; Argument[0].Field[alloc::string::String::vec]; ReturnValue; value |
| 20 | Summary: <core::convert::Into>::into; Argument[self].Reference.Element; ReturnValue.Element; taint |
| 21 | Summary: <core::str>::as_bytes; Argument[self].Reference; ReturnValue.Reference; taint |
| 22 | Summary: <generic_array::GenericArray>::from_slice; Argument[0].Reference; ReturnValue.Reference; value |
| 23 | Summary: alloc::vec::from_elem; Argument[0]; ReturnValue.Element; value |
| 20 | Summary: <core::str>::as_bytes; Argument[self].Reference; ReturnValue.Reference; taint |
| 21 | Summary: <generic_array::GenericArray>::from_slice; Argument[0].Reference; ReturnValue.Reference; value |
| 22 | Summary: alloc::vec::from_elem; Argument[0]; ReturnValue.Element; value |
nodes
| test_cipher.rs:18:9:18:14 | const1 [&ref] | semmle.label | const1 [&ref] |
| test_cipher.rs:18:28:18:36 | &... [&ref] | semmle.label | &... [&ref] |
Expand Down
Loading