Skip to content

Commit e086f8d

Browse files
committed
Rust: Calculate canonical paths in QL
1 parent 13f4a6a commit e086f8d

File tree

9 files changed

+436
-24
lines changed

9 files changed

+436
-24
lines changed

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowConsistency.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,25 @@ private module Input implements InputSig<Location, RustDataFlow> {
2929
}
3030

3131
import MakeConsistency<Location, RustDataFlow, RustTaintTracking, Input>
32+
private import codeql.rust.dataflow.internal.ModelsAsData
33+
34+
query predicate missingMadSummaryCanonicalPath(string crate, string path, Addressable a) {
35+
summaryModel(crate, path, _, _, _, _, _) and
36+
a.getCrateOrigin() = crate and
37+
a.getExtendedCanonicalPath() = path and
38+
not exists(a.getCanonicalPath())
39+
}
40+
41+
query predicate missingMadSourceCanonicalPath(string crate, string path, Addressable a) {
42+
sourceModel(crate, path, _, _, _, _) and
43+
a.getCrateOrigin() = crate and
44+
a.getExtendedCanonicalPath() = path and
45+
not exists(a.getCanonicalPath())
46+
}
47+
48+
query predicate missingMadSinkCanonicalPath(string crate, string path, Addressable a) {
49+
sinkModel(crate, path, _, _, _, _) and
50+
a.getCrateOrigin() = crate and
51+
a.getExtendedCanonicalPath() = path and
52+
not exists(a.getCanonicalPath())
53+
}

rust/ql/lib/codeql/rust/elements/internal/AddressableImpl.qll

Lines changed: 33 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qll

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,7 @@ private class StartswithCall extends Path::SafeAccessCheck::Range, CfgNodes::Met
2828
* [1]: https://doc.rust-lang.org/std/option/enum.Option.html
2929
*/
3030
class OptionEnum extends Enum {
31-
OptionEnum() {
32-
// todo: replace with canonical path, once calculated in QL
33-
exists(Crate core, Module m |
34-
core.getName() = "core" and
35-
m = core.getModule().getItemList().getAnItem() and
36-
m.getName().getText() = "option" and
37-
this = m.getItemList().getAnItem() and
38-
this.getName().getText() = "Option"
39-
)
40-
}
31+
OptionEnum() { this.getCanonicalPath() = "core::option::Option" }
4132

4233
/** Gets the `Some` variant. */
4334
Variant getSome() { result = this.getVariant("Some") }
@@ -49,16 +40,7 @@ class OptionEnum extends Enum {
4940
* [1]: https://doc.rust-lang.org/stable/std/result/enum.Result.html
5041
*/
5142
class ResultEnum extends Enum {
52-
ResultEnum() {
53-
// todo: replace with canonical path, once calculated in QL
54-
exists(Crate core, Module m |
55-
core.getName() = "core" and
56-
m = core.getModule().getItemList().getAnItem() and
57-
m.getName().getText() = "result" and
58-
this = m.getItemList().getAnItem() and
59-
this.getName().getText() = "Result"
60-
)
61-
}
43+
ResultEnum() { this.getCanonicalPath() = "core::result::Result" }
6244

6345
/** Gets the `Ok` variant. */
6446
Variant getOk() { result = this.getVariant("Ok") }

0 commit comments

Comments
 (0)