Skip to content

Commit bcb3863

Browse files
authored
Merge branch 'main' into redsun82/rust-regenerate-models
2 parents 16b9bec + 29b37a4 commit bcb3863

File tree

36 files changed

+435
-2148
lines changed

36 files changed

+435
-2148
lines changed

java/ql/integration-tests/java/query-suite/java-code-quality-extended.qls.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
ql/java/ql/src/Advisory/Declarations/MissingOverrideAnnotation.ql
2-
ql/java/ql/src/Advisory/Deprecated Code/AvoidDeprecatedCallableAccess.ql
32
ql/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql
43
ql/java/ql/src/Advisory/Documentation/SpuriousJavadocParam.ql
54
ql/java/ql/src/Compatibility/JDK9/JdkInternalAccess.ql

java/ql/integration-tests/java/query-suite/java-code-quality.qls.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
ql/java/ql/src/Advisory/Declarations/MissingOverrideAnnotation.ql
2-
ql/java/ql/src/Advisory/Deprecated Code/AvoidDeprecatedCallableAccess.ql
32
ql/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql
43
ql/java/ql/src/Advisory/Documentation/SpuriousJavadocParam.ql
54
ql/java/ql/src/Compatibility/JDK9/JdkInternalAccess.ql

java/ql/src/Advisory/Deprecated Code/AvoidDeprecatedCallableAccess.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* @problem.severity recommendation
77
* @precision high
88
* @id java/deprecated-call
9-
* @tags quality
10-
* maintainability
9+
* @tags maintainability
1110
* readability
1211
* non-attributable
1312
* external/cwe/cwe-477

javascript/ql/lib/semmle/javascript/frameworks/Fastify.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
2-
* Provides classes for working with [Fastify](https://www.fastify.io/) applications.
2+
* Provides classes for working with [Fastify](https://www.fastify.dev/) applications.
33
*/
44

55
import javascript
66
import semmle.javascript.frameworks.HTTP
77

88
/**
9-
* Provides classes for working with [Fastify](https://www.fastify.io/) applications.
9+
* Provides classes for working with [Fastify](https://www.fastify.dev/) applications.
1010
*/
1111
module Fastify {
1212
/**

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/elements/internal/AstNodeImpl.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ module Impl {
7070
*/
7171
pragma[nomagic]
7272
predicate isFromMacroExpansion() {
73-
exists(MacroCall mc |
74-
MacroCallImpl::isInMacroExpansion(mc, this) and
75-
not this = mc.getATokenTreeNode()
73+
exists(AstNode root |
74+
MacroCallImpl::isInMacroExpansion(root, this) and
75+
not this = root.(MacroCall).getATokenTreeNode()
7676
)
7777
}
7878

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ module Impl {
1414
private import rust
1515

1616
pragma[nomagic]
17-
predicate isInMacroExpansion(MacroCall mc, AstNode n) {
18-
n = mc.getMacroCallExpansion()
17+
predicate isInMacroExpansion(AstNode root, AstNode n) {
18+
n = root.(MacroCall).getMacroCallExpansion()
1919
or
20-
isInMacroExpansion(mc, n.getParentNode())
20+
n = root.(Adt).getDeriveMacroExpansion(_)
21+
or
22+
isInMacroExpansion(root, n.getParentNode())
2123
}
2224

2325
// the following QLdoc is generated: if you need to edit it, do it in the schema file

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ module Impl {
3434
exists(this.getField(pragma[only_bind_into](pos)))
3535
}
3636

37+
/**
38+
* Gets the struct matched by this pattern.
39+
*/
40+
Struct getStruct() { result = PathResolution::resolvePath(this.getPath()) }
41+
3742
/** Gets the tuple field that matches the `pos`th pattern of this pattern. */
3843
pragma[nomagic]
3944
TupleField getTupleField(int pos) {

rust/ql/lib/codeql/rust/frameworks/Poem.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44

55
private import rust
66
private import codeql.rust.Concepts
7-
private import codeql.rust.dataflow.DataFlow
87

98
/**
109
* Parameters of a handler function
1110
*/
1211
private class PoemHandlerParam extends RemoteSource::Range {
1312
PoemHandlerParam() {
1413
exists(TupleStructPat param |
15-
param.getResolvedPath() = ["crate::web::query::Query", "crate::web::path::Path"]
16-
|
17-
this.asPat().getPat() = param.getAField()
14+
this.asPat().getPat() = param.getAField() and
15+
param.getStruct().getCanonicalPath() = ["poem::web::query::Query", "poem::web::path::Path"]
1816
)
1917
}
2018
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ pragma[nomagic]
11321132
private predicate crateDependencyEdge(SourceFileItemNode file, string name, CrateItemNode dep) {
11331133
exists(CrateItemNode c | dep = c.(Crate).getDependency(name) | file = c.getASourceFile())
11341134
or
1135-
// Give builtin files, such as `await.rs`, access to `std`
1135+
// Give builtin files access to `std`
11361136
file instanceof BuiltinSourceFile and
11371137
dep.getName() = name and
11381138
name = "std"
@@ -1501,7 +1501,7 @@ private predicate preludeEdge(SourceFile f, string name, ItemNode i) {
15011501
exists(Crate stdOrCore, ModuleLikeNode mod, ModuleItemNode prelude, ModuleItemNode rust |
15021502
f = any(Crate c0 | stdOrCore = c0.getDependency(_) or stdOrCore = c0).getASourceFile()
15031503
or
1504-
// Give builtin files, such as `await.rs`, access to the prelude
1504+
// Give builtin files access to the prelude
15051505
f instanceof BuiltinSourceFile
15061506
|
15071507
stdOrCore.getName() = ["std", "core"] and

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)

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

Lines changed: 14 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -997,101 +997,31 @@ private AssociatedTypeTypeParameter getFutureOutputTypeParameter() {
997997
result.getTypeAlias() = any(FutureTrait ft).getOutputType()
998998
}
999999

1000-
/**
1001-
* A matching configuration for resolving types of `.await` expressions.
1002-
*/
1003-
private module AwaitExprMatchingInput implements MatchingInputSig {
1004-
private newtype TDeclarationPosition =
1005-
TSelfDeclarationPosition() or
1006-
TOutputPos()
1007-
1008-
class DeclarationPosition extends TDeclarationPosition {
1009-
predicate isSelf() { this = TSelfDeclarationPosition() }
1010-
1011-
predicate isOutput() { this = TOutputPos() }
1012-
1013-
string toString() {
1014-
this.isSelf() and
1015-
result = "self"
1016-
or
1017-
this.isOutput() and
1018-
result = "(output)"
1019-
}
1020-
}
1021-
1022-
private class BuiltinsAwaitFile extends File {
1023-
BuiltinsAwaitFile() {
1024-
this.getBaseName() = "await.rs" and
1025-
this.getParentContainer() instanceof Builtins::BuiltinsFolder
1026-
}
1027-
}
1028-
1029-
class Declaration extends Function {
1030-
Declaration() {
1031-
this.getFile() instanceof BuiltinsAwaitFile and
1032-
this.getName().getText() = "await_type_matching"
1033-
}
1034-
1035-
TypeParameter getTypeParameter(TypeParameterPosition ppos) {
1036-
typeParamMatchPosition(this.getGenericParamList().getATypeParam(), result, ppos)
1037-
}
1038-
1039-
Type getDeclaredType(DeclarationPosition dpos, TypePath path) {
1040-
dpos.isSelf() and
1041-
result = this.getParam(0).getTypeRepr().(TypeMention).resolveTypeAt(path)
1042-
or
1043-
dpos.isOutput() and
1044-
result = this.getRetType().getTypeRepr().(TypeMention).resolveTypeAt(path)
1045-
}
1046-
}
1047-
1048-
class AccessPosition = DeclarationPosition;
1049-
1050-
class Access extends AwaitExpr {
1051-
Type getTypeArgument(TypeArgumentPosition apos, TypePath path) { none() }
1052-
1053-
AstNode getNodeAt(AccessPosition apos) {
1054-
result = this.getExpr() and
1055-
apos.isSelf()
1056-
or
1057-
result = this and
1058-
apos.isOutput()
1059-
}
1060-
1061-
Type getInferredType(AccessPosition apos, TypePath path) {
1062-
result = inferType(this.getNodeAt(apos), path)
1063-
}
1064-
1065-
Declaration getTarget() { exists(this) and exists(result) }
1066-
}
1067-
1068-
predicate accessDeclarationPositionMatch(AccessPosition apos, DeclarationPosition dpos) {
1069-
apos = dpos
1070-
}
1071-
}
1072-
10731000
pragma[nomagic]
10741001
private TraitType inferAsyncBlockExprRootType(AsyncBlockExpr abe) {
10751002
// `typeEquality` handles the non-root case
10761003
exists(abe) and
10771004
result = getFutureTraitType()
10781005
}
10791006

1080-
private module AwaitExprMatching = Matching<AwaitExprMatchingInput>;
1007+
final class AwaitTarget extends Expr {
1008+
AwaitTarget() { this = any(AwaitExpr ae).getExpr() }
1009+
1010+
Type getTypeAt(TypePath path) { result = inferType(this, path) }
1011+
}
1012+
1013+
private module AwaitSatisfiesConstraintInput implements SatisfiesConstraintInputSig<AwaitTarget> {
1014+
predicate relevantConstraint(AwaitTarget term, Type constraint) {
1015+
exists(term) and
1016+
constraint.(TraitType).getTrait() instanceof FutureTrait
1017+
}
1018+
}
10811019

10821020
pragma[nomagic]
10831021
private Type inferAwaitExprType(AstNode n, TypePath path) {
1084-
exists(AwaitExprMatchingInput::Access a, AwaitExprMatchingInput::AccessPosition apos |
1085-
n = a.getNodeAt(apos) and
1086-
result = AwaitExprMatching::inferAccessType(a, apos, path)
1087-
)
1088-
or
1089-
// This case is needed for `async` functions and blocks, where we assign
1090-
// the type `Future<Output = T>` directly instead of `impl Future<Output = T>`
1091-
//
1092-
// TODO: It would be better if we could handle this in the shared library
10931022
exists(TypePath exprPath |
1094-
result = inferType(n.(AwaitExpr).getExpr(), exprPath) and
1023+
SatisfiesConstraint<AwaitTarget, AwaitSatisfiesConstraintInput>::satisfiesConstraintType(n.(AwaitExpr)
1024+
.getExpr(), _, exprPath, result) and
10951025
exprPath.isCons(getFutureOutputTypeParameter(), path)
10961026
)
10971027
}

rust/ql/test/extractor-tests/crate_graph/CONSISTENCY/PathResolutionConsistency.expected

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
multipleCallTargets
2+
| proc_macro.rs:16:12:16:16 | ...::to_tokens(...) |
3+
| proc_macro.rs:26:10:26:12 | ...::to_tokens(...) |
4+
| proc_macro.rs:27:10:27:16 | ...::to_tokens(...) |
5+
| proc_macro.rs:42:16:42:26 | ...::to_tokens(...) |
6+
| proc_macro.rs:44:27:44:30 | ...::to_tokens(...) |
7+
| proc_macro.rs:46:18:46:28 | ...::to_tokens(...) |
18
multiplePathResolutions
2-
| macro_expansion.rs:1:5:1:14 | proc_macro | file://:0:0:0:0 | Crate([email protected]) |
3-
| macro_expansion.rs:1:5:1:14 | proc_macro | proc_macro.rs:0:0:0:0 | Crate([email protected]) |
9+
| macro_expansion.rs:1:5:1:14 | proc_macro |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
multipleCallTargets
2+
| main.rs:225:14:225:29 | ...::deref(...) |
Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
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:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
10-
| main.rs:532:10:532:18 | ...::from | file://:0:0:0:0 | fn from |
11-
| main.rs:532:10:532: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 |
16-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
17-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
18-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
19-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
20-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
21-
| main.rs:538:10:538:18 | ...::from | file://:0:0:0:0 | fn from |
1+
multipleCallTargets
2+
| main.rs:532:10:532:21 | ...::from(...) |
3+
| main.rs:538:10:538:21 | ...::from(...) |

0 commit comments

Comments
 (0)