File tree Expand file tree Collapse file tree 8 files changed +30
-41
lines changed
test/query-tests/security/CWE-079/actix Expand file tree Collapse file tree 8 files changed +30
-41
lines changed Original file line number Diff line number Diff line change @@ -8,34 +8,7 @@ private import internal.CallExprImpl::Impl as CallExprImpl
88
99final class Call = Impl:: Call ;
1010
11- private predicate isGuaranteedMethodCall ( ArgsExpr call ) {
12- call instanceof MethodCallExpr
13- or
14- call .( Operation ) .isOverloaded ( _, _, _)
15- or
16- call instanceof IndexExpr
17- }
18-
19- /**
20- * A call expression that targets a method.
21- *
22- * Either
23- *
24- * - a `CallExpr` where we can resolve the target as a method,
25- * - a `MethodCallExpr`,
26- * - an `Operation` that targets an overloadable operator, or
27- * - an `IndexExpr`.
28- */
29- final class MethodCall extends Call {
30- MethodCall ( ) {
31- this .getStaticTarget ( ) instanceof Method
32- or
33- isGuaranteedMethodCall ( this )
34- }
35-
36- /** Gets the static target of this method call, if any. */
37- Method getStaticTarget ( ) { result = super .getStaticTarget ( ) }
38- }
11+ final class MethodCall = Impl:: MethodCall ;
3912
4013/**
4114 * A call expression that targets a closure.
Original file line number Diff line number Diff line change @@ -72,15 +72,15 @@ module Impl {
7272 )
7373 }
7474
75- private predicate isMethodCall ( ) { this .getResolvedTarget ( ) instanceof Method }
75+ override Expr getPositionalArgument ( int i ) { result = super .getSyntacticArgument ( i ) }
76+ }
7677
77- override Expr getPositionalArgument ( int i ) {
78- if this .isMethodCall ( )
79- then result = this .getSyntacticArgument ( i + 1 )
80- else result = super .getSyntacticArgument ( i )
81- }
78+ class CallExprMethodCall extends CallExprCall , CallImpl:: MethodCall {
79+ CallExprMethodCall ( ) { this .getResolvedTarget ( ) instanceof Method }
80+
81+ override Expr getPositionalArgument ( int i ) { result = this .getSyntacticArgument ( i + 1 ) }
8282
83- override Expr getReceiver ( ) { this . isMethodCall ( ) and result = super .getSyntacticArgument ( 0 ) }
83+ override Expr getReceiver ( ) { result = super .getSyntacticArgument ( 0 ) }
8484 }
8585
8686 /**
Original file line number Diff line number Diff line change @@ -69,4 +69,18 @@ module Impl {
6969 )
7070 }
7171 }
72+
73+ /**
74+ * A call expression that targets a method.
75+ *
76+ * Either
77+ *
78+ * - a `CallExpr` where we can resolve the target as a method,
79+ * - a `MethodCallExpr`,
80+ * - an `Operation` that targets an overloadable operator, or
81+ * - an `IndexExpr`.
82+ */
83+ abstract class MethodCall extends Call {
84+ override Method getStaticTarget ( ) { result = super .getStaticTarget ( ) }
85+ }
7286}
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ module Impl {
2222 * list[42] = 1;
2323 * ```
2424 */
25- class IndexExpr extends Generated:: IndexExpr , CallImpl:: Call {
25+ class IndexExpr extends Generated:: IndexExpr , CallImpl:: MethodCall {
2626 override string toStringImpl ( ) {
2727 result =
2828 this .getBase ( ) .toAbbreviatedString ( ) + "[" + this .getIndex ( ) .toAbbreviatedString ( ) + "]"
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ module Impl {
2727 * x.foo::<u32, u64>(42);
2828 * ```
2929 */
30- class MethodCallExpr extends Generated:: MethodCallExpr , CallImpl:: Call {
30+ class MethodCallExpr extends Generated:: MethodCallExpr , CallImpl:: MethodCall {
3131 private string toStringPart ( int index ) {
3232 index = 0 and
3333 result = this .getReceiver ( ) .toAbbreviatedString ( )
Original file line number Diff line number Diff line change @@ -137,8 +137,8 @@ module Impl {
137137 }
138138 }
139139
140- private class CallOperation extends CallImpl:: Call instanceof Operation {
141- CallOperation ( ) { super .isOverloaded ( _, _, _) }
140+ private class OperationMethodCall extends CallImpl:: MethodCall instanceof Operation {
141+ OperationMethodCall ( ) { super .isOverloaded ( _, _, _) }
142142
143143 override Expr getPositionalArgument ( int i ) { result = super .getOperand ( i + 1 ) and i >= 0 }
144144
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ module Xss {
5555 HeuristicHtmlEncodingBarrier ( ) {
5656 exists ( Call fc |
5757 fc .getStaticTarget ( ) .getName ( ) .getText ( ) .regexpMatch ( ".*(escape|encode).*" ) and
58- fc .getArgument ( _ ) = this .asExpr ( )
58+ fc .getAPositionalArgument ( ) = this .asExpr ( )
5959 )
6060 }
6161 }
Original file line number Diff line number Diff line change 22| main.rs:25:5:25:13 | ...::new | main.rs:8:1:8:18 | to | main.rs:25:5:25:13 | ...::new | Cross-site scripting vulnerability due to a $@. | main.rs:8:1:8:18 | to | user-provided value |
33edges
44| main.rs:8:1:8:18 | to | main.rs:9:29:9:51 | ...: ...::Path::<...> | provenance | Src:MaD:2 |
5- | main.rs:9:29:9:51 | ...: ...::Path::<...> | main.rs:10:22:10:38 | path.into_inner() | provenance | MaD:3 |
5+ | main.rs:9:29:9:51 | ...: ...::Path::<...> | main.rs:10:22:10:25 | path | provenance | |
66| main.rs:10:9:10:18 | user_input | main.rs:13:9:22:18 | MacroExpr | provenance | |
7+ | main.rs:10:22:10:25 | path | main.rs:10:22:10:38 | path.into_inner() | provenance | MaD:3 |
78| main.rs:10:22:10:38 | path.into_inner() | main.rs:10:9:10:18 | user_input | provenance | |
89| main.rs:12:9:12:12 | html | main.rs:25:15:25:18 | html | provenance | |
910| main.rs:13:9:22:18 | ...::format(...) | main.rs:13:9:22:18 | { ... } | provenance | |
2122| main.rs:8:1:8:18 | to | semmle.label | to |
2223| main.rs:9:29:9:51 | ...: ...::Path::<...> | semmle.label | ...: ...::Path::<...> |
2324| main.rs:10:9:10:18 | user_input | semmle.label | user_input |
25+ | main.rs:10:22:10:25 | path | semmle.label | path |
2426| main.rs:10:22:10:38 | path.into_inner() | semmle.label | path.into_inner() |
2527| main.rs:12:9:12:12 | html | semmle.label | html |
2628| main.rs:13:9:22:18 | ...::format(...) | semmle.label | ...::format(...) |
You can’t perform that action at this time.
0 commit comments