8000 C#: Improve arg-param mapping logic to consider named arguments passe… · github/codeql@7daeeef · GitHub
[go: up one dir, main page]

Skip to content

Commit 7daeeef

Browse files
committed
C#: Improve arg-param mapping logic to consider named arguments passed to params parameters
1 parent 9bb8074 commit 7daeeef

File tree

4 files changed

+4
-24
lines changed

4 files changed

+4
-24
lines changed

csharp/ql/lib/semmle/code/csharp/exprs/Call.qll

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ class Call extends DotNet::Call, Expr, @call {
6666
result = this.getImplicitArgument(p)
6767
or
6868
// Appears in the named part of the call
69-
result = this.getExplicitArgument(p.getName()) and
70-
(p.(Parameter).isParams() implies isValidExplicitParamsType(p, result.getType()))
69+
result = this.getExplicitArgument(p.getName())
7170
)
7271
}
7372

@@ -224,28 +223,6 @@ class Call extends DotNet::Call, Expr, @call {
224223
override string toString() { result = "call" }
225224
}
226225

227-
/**
228-
* Holds if the type `t` is a valid argument type for passing an explicit array
229-
* to the `params` parameter `p`. For example, the types `object[]` and `string[]`
230-
* of the arguments on lines 4 and 5, respectively, are valid for the parameter
231-
* `args` on line 1 in
232-
*
233-
* ```csharp
234-
* void M(params object[] args) { ... }
235-
*
236-
* void CallM(object[] os, string[] ss, string s) {
237-
* M(os);
238-
* M(ss);
239-
* M(s);
240-
* }
241-
* ```
242-
*/
243-
pragma[nomagic]
244-
private predicate isValidExplicitParamsType(Parameter p, Type t) {
245-
p.isParams() and
246-
t.isImplicitlyConvertibleTo(p.getType())
247-
}
248-
249226
/**
250227
* A method call, for example `a.M()` on line 5 in
251228
*

csharp/ql/test/library-tests/arguments/argumentByName.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
| arguments.cs:35:9:35:19 | call to method f3 | arguments.cs:35:18:35:18 | 2 | args |
1313
| arguments.cs:36:9:36:33 | call to method f3 | arguments.cs:36:12:36:12 | 0 | o |
1414
| arguments.cs:36:9:36:33 | call to method f3 | arguments.cs:36:15:36:32 | array creation of type Int32[] | args |
15+
| arguments.cs:37:9:37:25 | call to method f3 | arguments.cs:37:18:37:18 | 1 | args |
1516
| arguments.cs:37:9:37:25 | call to method f3 | arguments.cs:37:24:37:24 | 0 | o |
1617
| arguments.cs:38:9:38:19 | call to method f3 | arguments.cs:38:12:38:12 | 0 | o |
1718
| arguments.cs:38:9:38:19 | call to method f3 | arguments.cs:38:15:38:18 | access to parameter args | args |

csharp/ql/test/library-tests/arguments/argumentByParameter.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
| arguments.cs:35:9:35:19 | call to method f3 | arguments.cs:35:18:35:18 | 2 | arguments.cs:33:33:33:36 | args |
1313
| arguments.cs:36:9:36:33 | call to method f3 | arguments.cs:36:12:36:12 | 0 | arguments.cs:33:17:33:17 | o |
1414
| arguments.cs:36:9:36:33 | call to method f3 | arguments.cs:36:15:36:32 | array creation of type Int32[] | arguments.cs:33:33:33:36 | args |
15+
| arguments.cs:37:9:37:25 | call to method f3 | arguments.cs:37:18:37:18 | 1 | arguments.cs:33:33:33:36 | args |
1516
| arguments.cs:37:9:37:25 | call to method f3 | arguments.cs:37:24:37:24 | 0 | arguments.cs:33:17:33:17 | o |
1617
| arguments.cs:38:9:38:19 | call to method f3 | arguments.cs:38:12:38:12 | 0 | arguments.cs:33:17:33:17 | o |
1718
| arguments.cs:38:9:38:19 | call to method f3 | arguments.cs:38:15:38:18 | access to parameter args | arguments.cs:33:33:33:36 | args |

csharp/ql/test/library-tests/arguments/parameterGetArguments.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
| arguments.cs:33:33:33:36 | args | arguments.cs:35:15:35:15 | 1 |
1818
| arguments.cs:33:33:33:36 | args | arguments.cs:35:18:35:18 | 2 |
1919
| arguments.cs:33:33:33:36 | args | arguments.cs:36:15:36:32 | array creation of type Int32[] |
20+
| arguments.cs:33:33:33:36 | args | arguments.cs:37:18:37:18 | 1 |
2021
| arguments.cs:33:33:33:36 | args | arguments.cs:38:15:38:18 | access to parameter args |
2122
| arguments.cs:33:33:33:36 | args | arguments.cs:39:18:39:21 | access to parameter args |
2223
| arguments.cs:33:33:33:36 | args | arguments.cs:40:18:40:35 | array creation of type Int32[] |

0 commit comments

Comments
 (0)
0