Skip to content

Commit bf39058

Browse files
authored
Merge pull request #19611 from hvitved/rust/path-resolution-std-prelude
Rust: Also take the `std` prelude into account when resolving paths
2 parents 2561f3c + 3fa308e commit bf39058

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

rust/ql/lib/codeql/rust/internal/PathResolution.qll

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,18 +1404,20 @@ private predicate useImportEdge(Use use, string name, ItemNode item) {
14041404
}
14051405

14061406
/**
1407-
* Holds if `i` is available inside `f` because it is reexported in [the prelude][1].
1407+
* Holds if `i` is available inside `f` because it is reexported in
1408+
* [the `core` prelude][1] or [the `std` prelude][2].
14081409
*
14091410
* We don't yet have access to prelude information from the extractor, so for now
14101411
* we include all the preludes for Rust: 2015, 2018, 2021, and 2024.
14111412
*
14121413
* [1]: https://doc.rust-lang.org/core/prelude/index.html
1414+
* [2]: https://doc.rust-lang.org/std/prelude/index.html
14131415
*/
14141416
private predicate preludeEdge(SourceFile f, string name, ItemNode i) {
1415-
exists(Crate core, ModuleLikeNode mod, ModuleItemNode prelude, ModuleItemNode rust |
1416-
f = any(Crate c0 | core = c0.getDependency(_) or core = c0).getASourceFile() and
1417-
core.getName() = "core" and
1418-
mod = core.getSourceFile() and
1417+
exists(Crate stdOrCore, ModuleLikeNode mod, ModuleItemNode prelude, ModuleItemNode rust |
1418+
f = any(Crate c0 | stdOrCore = c0.getDependency(_) or stdOrCore = c0).getASourceFile() and
1419+
stdOrCore.getName() = ["std", "core"] and
1420+
mod = stdOrCore.getSourceFile() and
14191421
prelude = mod.getASuccessorRec("prelude") and
14201422
rust = prelude.getASuccessorRec(["rust_2015", "rust_2018", "rust_2021", "rust_2024"]) and
14211423
i = rust.getASuccessorRec(name) and
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
multiplePathResolutions
2+
| main.rs:218:14:218:17 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
3+
| main.rs:218:14:218:17 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
4+
| main.rs:219:13:219:16 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
5+
| main.rs:219:13:219:16 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
6+
| main.rs:220:13:220:16 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
7+
| main.rs:220:13:220:16 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
8+
| main.rs:221:13:221:16 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
9+
| main.rs:221:13:221:16 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
10+
| main.rs:222:13:222:16 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
11+
| main.rs:222:13:222:16 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
12+
| main.rs:223:13:223:16 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
13+
| main.rs:223:13:223:16 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
14+
| main.rs:224:13:224:16 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
15+
| main.rs:224:13:224:16 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
multiplePathResolutions
2+
| deallocation.rs:106:16:106:19 | libc | file://:0:0:0:0 | Crate(libc@0.2.171) |
3+
| deallocation.rs:106:16:106:19 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
4+
| deallocation.rs:106:16:106:27 | ...::malloc | file://:0:0:0:0 | fn malloc |
5+
| deallocation.rs:106:16:106:27 | ...::malloc | file://:0:0:0:0 | fn malloc |
6+
| deallocation.rs:112:3:112:6 | libc | file://:0:0:0:0 | Crate(libc@0.2.171) |
7+
| deallocation.rs:112:3:112:6 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |
8+
| deallocation.rs:112:3:112:12 | ...::free | file://:0:0:0:0 | fn free |
9+
| deallocation.rs:112:3:112:12 | ...::free | file://:0:0:0:0 | fn free |
10+
| deallocation.rs:112:29:112:32 | libc | file://:0:0:0:0 | Crate(libc@0.2.171) |
11+
| deallocation.rs:112:29:112:32 | libc | file://:0:0:0:0 | Crate(libc@0.2.172) |

0 commit comments

Comments
 (0)