Skip to content

Commit 5150f78

Browse files
committed
Rust: Avoid overlapping path resolution consistency checks
1 parent 12cda86 commit 5150f78

File tree

17 files changed

+682
-548
lines changed

17 files changed

+682
-548
lines changed

rust/ql/consistency-queries/PathResolutionConsistency.ql

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,17 @@ private import codeql.rust.internal.PathResolution
1010
private import codeql.rust.internal.PathResolutionConsistency as PathResolutionConsistency
1111
private import codeql.rust.elements.Locatable
1212
private import codeql.Locations
13-
import PathResolutionConsistency
1413

1514
class SourceLocatable extends Locatable {
16-
Location getLocation() {
17-
if super.getLocation().fromSource()
18-
then result = super.getLocation()
19-
else result instanceof EmptyLocation
20-
}
15+
SourceLocatable() { this.fromSource() }
2116
}
2217

23-
query predicate multipleMethodCallTargets(SourceLocatable a, SourceLocatable b) {
24-
PathResolutionConsistency::multipleMethodCallTargets(a, b)
18+
query predicate multipleCallTargets(SourceLocatable a) {
19+
PathResolutionConsistency::multipleCallTargets(a, _)
2520
}
2621

27-
query predicate multiplePathResolutions(SourceLocatable a, SourceLocatable b) {
28-
PathResolutionConsistency::multiplePathResolutions(a, b)
22+
query predicate multiplePathResolutions(SourceLocatable a) {
23+
PathResolutionConsistency::multiplePathResolutions(a, _)
2924
}
3025

3126
query predicate multipleCanonicalPaths(SourceLocatable i, SourceLocatable c, string path) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ query predicate multiplePathResolutions(Path p, ItemNode i) {
1717
not use.isGlob() and
1818
not use.hasUseTreeList()
1919
).getPath() and
20+
// avoid overlap with `multipleCallTargets` below
21+
not p = any(CallExpr ce).getFunction().(PathExpr).getPath() and
2022
strictcount(resolvePath(p)) > 1
2123
}
2224

2325
/** Holds if `call` has multiple static call targets including `target`. */
24-
query predicate multipleMethodCallTargets(MethodCallExpr call, Callable target) {
26+
query predicate multipleCallTargets(CallExprBase call, Callable target) {
2527
target = call.getStaticTarget() and
2628
strictcount(call.getStaticTarget()) > 1
2729
}
@@ -51,8 +53,8 @@ int getPathResolutionInconsistencyCounts(string type) {
5153
type = "Multiple path resolutions" and
5254
result = count(Path p | multiplePathResolutions(p, _) | p)
5355
or
54-
type = "Multiple static method call targets" and
55-
result = count(CallExprBase call | multipleMethodCallTargets(call, _) | call)
56+
type = "Multiple static call targets" and
57+
result = count(CallExprBase call | multipleCallTargets(call, _) | call)
5658
or
5759
type = "Multiple record fields" and
5860
result = count(FieldExpr fe | multipleStructFields(fe, _) | fe)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
multipleCallTargets
2+
| proc_macro.rs:16:12:16:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
3+
| proc_macro.rs:16:12:16:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
4+
| proc_macro.rs:16:12:16:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
5+
| proc_macro.rs:16:12:16:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
6+
| proc_macro.rs:26:10:26:12 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
7+
| proc_macro.rs:26:10:26:12 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
8+
| proc_macro.rs:26:10:26:12 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
9+
| proc_macro.rs:26:10:26:12 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
10+
| proc_macro.rs:27:10:27:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
11+
| proc_macro.rs:27:10:27:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
12+
| proc_macro.rs:27:10:27:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
13+
| proc_macro.rs:27:10:27:16 | ...::to_tokens(...) | file://:0:0:0:0 | fn to_tokens |
114
multiplePathResolutions
215
| macro_expansion.rs:1:5:1:14 | proc_macro | file://:0:0:0:0 | Crate(proc_macro@0.0.0) |
316
| macro_expansion.rs:1:5:1:14 | proc_macro | proc_macro.rs:0:0:0:0 | Crate(proc_macro@0.0.1) |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
multipleCallTargets
2+
| main.rs:225:14:225:29 | ...::deref(...) | file://:0:0:0:0 | fn deref |
3+
| main.rs:225:14:225:29 | ...::deref(...) | file://:0:0:0:0 | fn deref |
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
multiplePathResolutions
2-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
3-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
4-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
5-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
6-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
7-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
8-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
9-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
10-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
11-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
12-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
13-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
14-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
15-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
1+
multipleCallTargets
2+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
3+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
4+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
5+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
6+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
7+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
8+
| main.rs:532:10:532:21 | ...::from(...) | file://:0:0:0:0 | fn from |
9+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |
10+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |
11+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |
12+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |
13+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |
14+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |
15+
| main.rs:538:10:538:21 | ...::from(...) | file://:0:0:0:0 | fn from |

0 commit comments

Comments
 (0)