Skip to content

Commit 31aeb97

Browse files
committed
wip
1 parent 9a9f367 commit 31aeb97

File tree

6 files changed

+22
-28
lines changed

6 files changed

+22
-28
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
602602

603603
Path getTraitPath() { result = super.getTrait().(PathTypeRepr).getPath() }
604604

605-
ItemNode resolveSelfTy() { result = resolvePath(this.getSelfPath()) }
605+
TypeItemNode resolveSelfTy() { result = resolvePath(this.getSelfPath()) }
606606

607607
TraitItemNode resolveTraitTy() { result = resolvePath(this.getTraitPath()) }
608608

@@ -691,7 +691,7 @@ class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
691691
}
692692
}
693693

694-
private class ImplTraitTypeReprItemNode extends ItemNode instanceof ImplTraitTypeRepr {
694+
private class ImplTraitTypeReprItemNode extends TypeItemNode instanceof ImplTraitTypeRepr {
695695
pragma[nomagic]
696696
Path getABoundPath() {
697697
result = super.getTypeBoundList().getABound().getTypeRepr().(PathTypeRepr).getPath()
@@ -1350,7 +1350,17 @@ private predicate pathUsesNamespace(Path p, Namespace n) {
13501350
/** Gets the item that `path` resolves to, if any. */
13511351
cached
13521352
ItemNode resolvePath(RelevantPath path) {
1353-
exists(Namespace ns | result = resolvePath0(path, ns, _) |
1353+
exists(Namespace ns |
1354+
result = resolvePath0(path, ns, _) and
1355+
if path = any(ImplItemNode i).getSelfPath()
1356+
then
1357+
result instanceof TypeItemNode and
1358+
not result instanceof TraitItemNode
1359+
else
1360+
if path = any(ImplItemNode i).getTraitPath()
1361+
then result instanceof TraitItemNode
1362+
else any()
1363+
|
13541364
pathUsesNamespace(path, ns)
13551365
or
13561366
not pathUsesNamespace(path, _) and

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,9 @@ private import M2
224224
module Consistency {
225225
import M2::Consistency
226226

227-
query predicate nonUniqueCertainType(AstNode n, TypePath path) {
228-
strictcount(CertainTypeInference::inferCertainType(n, path)) > 1
227+
predicate nonUniqueCertainType(AstNode n, TypePath path, Type t) {
228+
strictcount(CertainTypeInference::inferCertainType(n, path)) > 1 and
229+
t = CertainTypeInference::inferCertainType(n, path)
229230
}
230231
}
231232

@@ -2513,7 +2514,6 @@ private module Debug {
25132514

25142515
Type debugInferCertainNonUniqueType(AstNode n, TypePath path) {
25152516
n = getRelevantLocatable() and
2516-
Consistency::nonUniqueCertainType(n, path) and
2517-
result = CertainTypeInference::inferCertainType(n, path)
2517+
Consistency::nonUniqueCertainType(n, path, result)
25182518
}
25192519
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ query predicate illFormedTypeMention(TypeMention tm) {
1717
tm.fromSource()
1818
}
1919

20+
query predicate nonUniqueCertainType(AstNode n, TypePath path) {
21+
Consistency::nonUniqueCertainType(n, path, _)
22+
}
23+
2024
int getTypeInferenceInconsistencyCounts(string type) {
2125
type = "Missing type parameter ID" and
2226
result = count(TypeParameter tp | missingTypeParameterId(tp) | tp)
@@ -31,5 +35,5 @@ int getTypeInferenceInconsistencyCounts(string type) {
3135
result = count(TypeMention tm | illFormedTypeMention(tm) | tm)
3236
or
3337
type = "Non-unique certain type information" and
34-
result = count(AstNode n, TypePath path | nonUniqueCertainType(n, path) | n)
38+
result = count(AstNode n, TypePath path | nonUniqueCertainType(n, path, _) | n)
3539
}
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
nonUniqueCertainType
2-
| file:///home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.31/src/future/future/flatten.rs:46:13:46:36 | SelfParam | Ptr.&T.Fut2 |
3-
| file:///home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.31/src/future/future/flatten.rs:84:18:84:41 | SelfParam | Ptr.&T.Fut2 |
4-
| file:///home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.31/src/future/future/flatten.rs:112:19:112:42 | SelfParam | Ptr.&T.Fut2 |
5-
| file:///home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.31/src/future/future/flatten.rs:127:19:127:38 | SelfParam | Ptr.&T.Fut2 |
6-
| file:///home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.31/src/future/future/flatten.rs:135:19:135:38 | SelfParam | Ptr.&T.Fut2 |
7-
| file:///home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.31/src/future/future/flatten.rs:143:19:143:42 | SelfParam | Ptr.&T.Fut2 |
82
| web_frameworks.rs:139:30:139:39 | ...::get(...) | |
93
| web_frameworks.rs:140:34:140:43 | ...::get(...) | |
104
| web_frameworks.rs:141:30:141:39 | ...::get(...) | |

rust/ql/test/query-tests/security/CWE-089/CONSISTENCY/TypeInferenceConsistency.expected

Lines changed: 0 additions & 7 deletions
This file was deleted.

rust/ql/test/query-tests/security/CWE-311/CONSISTENCY/TypeInferenceConsistency.expected

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)