Skip to content

Commit 6d6150d

Browse files
committed
C#: Change some data-flow toString()s
1 parent 3c26779 commit 6d6150d

File tree

17 files changed

+3710
-3702
lines changed

17 files changed

+3710
-3702
lines changed

csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ abstract class ReturnKind extends TReturnKind {
175175
* body, that is, a "normal" return.
176176
*/
177177
class NormalReturnKind extends ReturnKind, TNormalReturnKind {
178-
override string toString() { result = "return" }
178+
override string toString() { result = "normal" }
179179
}
180180

181181
/** A value returned from a callable using an `out` or a `ref` parameter. */
@@ -186,16 +186,24 @@ abstract class OutRefReturnKind extends ReturnKind {
186186

187187
/** A value returned from a callable using an `out` parameter. */
188188
class OutReturnKind extends OutRefReturnKind, TOutReturnKind {
189-
override int getPosition() { this = TOutReturnKind(result) }
189+
private int pos;
190+
191+
OutReturnKind() { this = TOutReturnKind(pos) }
192+
193+
override int getPosition() { result = pos }
190194

191-
override string toString() { result = "out" }
195+
override string toString() { result = "out parameter " + pos }
192196
}
193197

194198
/** A value returned from a callable using a `ref` parameter. */
195199
class RefReturnKind extends OutRefReturnKind, TRefReturnKind {
196-
override int getPosition() { this = TRefReturnKind(result) }
200+
private int pos;
201+
202+
RefReturnKind() { this = TRefReturnKind(pos) }
203+
204+
override int getPosition() { result = pos }
197205

198-
override string toString() { result = "ref" }
206+
override string toString() { result = "ref parameter " + pos }
199207
}
200208

201209
/** A value implicitly returned from a callable using a captured variable. */

csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowPublic.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class FieldContent extends Content, TFieldContent {
236236
/** Gets the field that is referenced. */
237237
Field getField() { result = f }
238238

239-
override string toString() { result = f.toString() }
239+
override string toString() { result = "field " + f.getName() }
240240

241241
override Location getLocation() { result = f.getLocation() }
242242

@@ -256,7 +256,7 @@ class PropertyContent extends Content, TPropertyContent {
256256
/** Gets the property that is referenced. */
257257
Property getProperty() { result = p }
258258

259-
override string toString() { result = p.toString() }
259+
override string toString() { result = "property " + p.getName() }
260260

261261
override Location getLocation() { result = p.getLocation() }
262262

@@ -269,7 +269,7 @@ class PropertyContent extends Content, TPropertyContent {
269269

270270
/** A reference to an element in a collection. */
271271
class ElementContent extends Content, TElementContent {
272-
override string toString() { result = "[]" }
272+
override string toString() { result = "element" }
273273

274274
override Location getLocation() { result instanceof EmptyLocation }
275275
}

csharp/ql/test/library-tests/csharp7/GlobalFlow.expected

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ edges
44
| CSharp7.cs:51:22:51:23 | SSA def(t1) : String | CSharp7.cs:53:18:53:19 | access to local variable t1 |
55
| CSharp7.cs:57:11:57:19 | "tainted" : String | CSharp7.cs:57:30:57:31 | SSA def(t4) : String |
66
| CSharp7.cs:57:30:57:31 | SSA def(t4) : String | CSharp7.cs:58:18:58:19 | access to local variable t4 |
7-
| CSharp7.cs:89:18:89:34 | (..., ...) [Item1] : String | CSharp7.cs:92:20:92:21 | access to local variable t1 [Item1] : String |
8-
| CSharp7.cs:89:19:89:27 | "tainted" : String | CSharp7.cs:89:18:89:34 | (..., ...) [Item1] : String |
9-
| CSharp7.cs:92:20:92:21 | access to local variable t1 [Item1] : String | CSharp7.cs:92:20:92:27 | access to field Item1 : String |
7+
| CSharp7.cs:89:18:89:34 | (..., ...) [field Item1] : String | CSharp7.cs:92:20:92:21 | access to local variable t1 [field Item1] : String |
8+
| CSharp7.cs:89:19:89:27 | "tainted" : String | CSharp7.cs:89:18:89:34 | (..., ...) [field Item1] : String |
9+
| CSharp7.cs:92:20:92:21 | access to local variable t1 [field Item1] : String | CSharp7.cs:92:20:92:27 | access to field Item1 : String |
1010
| CSharp7.cs:92:20:92:27 | access to field Item1 : String | CSharp7.cs:92:18:92:28 | call to method I |
1111
| CSharp7.cs:177:22:177:30 | "tainted" : String | CSharp7.cs:183:23:183:25 | access to local variable src : String |
1212
| CSharp7.cs:177:22:177:30 | "tainted" : String | CSharp7.cs:184:23:184:25 | access to local variable src : String |
@@ -20,10 +20,10 @@ nodes
2020
| CSharp7.cs:57:11:57:19 | "tainted" : String | semmle.label | "tainted" : String |
2121
| CSharp7.cs:57:30:57:31 | SSA def(t4) : String | semmle.label | SSA def(t4) : String |
2222
| CSharp7.cs:58:18:58:19 | access to local variable t4 | semmle.label | access to local variable t4 |
23-
| CSharp7.cs:89:18:89:34 | (..., ...) [Item1] : String | semmle.label | (..., ...) [Item1] : String |
23+
| CSharp7.cs:89:18:89:34 | (..., ...) [field Item1] : String | semmle.label | (..., ...) [field Item1] : String |
2424
| CSharp7.cs:89:19:89:27 | "tainted" : String | semmle.label | "tainted" : String |
2525
| CSharp7.cs:92:18:92:28 | call to method I | semmle.label | call to method I |
26-
| CSharp7.cs:92:20:92:21 | access to local variable t1 [Item1] : String | semmle.label | access to local variable t1 [Item1] : String |
26+
| CSharp7.cs:92:20:92:21 | access to local variable t1 [field Item1] : String | semmle.label | access to local variable t1 [field Item1] : String |
2727
| CSharp7.cs:92:20:92:27 | access to field Item1 : String | semmle.label | access to field Item1 : String |
2828
| CSharp7.cs:177:22:177:30 | "tainted" | semmle.label | "tainted" |
2929
| CSharp7.cs:177:22:177:30 | "tainted" : String | semmle.label | "tainted" : String |

csharp/ql/test/library-tests/csharp7/GlobalTaintTracking.expected

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ edges
44
| CSharp7.cs:51:22:51:23 | SSA def(t1) : String | CSharp7.cs:53:18:53:19 | access to local variable t1 |
55
| CSharp7.cs:57:11:57:19 | "tainted" : String | CSharp7.cs:57:30:57:31 | SSA def(t4) : String |
66
| CSharp7.cs:57:30:57:31 | SSA def(t4) : String | CSharp7.cs:58:18:58:19 | access to local variable t4 |
7-
| CSharp7.cs:89:18:89:34 | (..., ...) [Item1] : String | CSharp7.cs:92:20:92:21 | access to local variable t1 [Item1] : String |
8-
| CSharp7.cs:89:19:89:27 | "tainted" : String | CSharp7.cs:89:18:89:34 | (..., ...) [Item1] : String |
9-
| CSharp7.cs:92:20:92:21 | access to local variable t1 [Item1] : String | CSharp7.cs:92:20:92:27 | access to field Item1 : String |
7+
| CSharp7.cs:89:18:89:34 | (..., ...) [field Item1] : String | CSharp7.cs:92:20:92:21 | access to local variable t1 [field Item1] : String |
8+
| CSharp7.cs:89:19:89:27 | "tainted" : String | CSharp7.cs:89:18:89:34 | (..., ...) [field Item1] : String |
9+
| CSharp7.cs:92:20:92:21 | access to local variable t1 [field Item1] : String | CSharp7.cs:92:20:92:27 | access to field Item1 : String |
1010
| CSharp7.cs:92:20:92:27 | access to field Item1 : String | CSharp7.cs:92:18:92:28 | call to method I |
1111
| CSharp7.cs:177:22:177:30 | "tainted" : String | CSharp7.cs:182:23:182:25 | access to local variable src : String |
1212
| CSharp7.cs:177:22:177:30 | "tainted" : String | CSharp7.cs:183:23:183:25 | access to local variable src : String |
@@ -22,10 +22,10 @@ nodes
2222
| CSharp7.cs:57:11:57:19 | "tainted" : String | semmle.label | "tainted" : String |
2323
| CSharp7.cs:57:30:57:31 | SSA def(t4) : String | semmle.label | SSA def(t4) : String |
2424
| CSharp7.cs:58:18:58:19 | access to local variable t4 | semmle.label | access to local variable t4 |
25-
| CSharp7.cs:89:18:89:34 | (..., ...) [Item1] : String | semmle.label | (..., ...) [Item1] : String |
25+
| CSharp7.cs:89:18:89:34 | (..., ...) [field Item1] : String | semmle.label | (..., ...) [field Item1] : String |
2626
| CSharp7.cs:89:19:89:27 | "tainted" : String | semmle.label | "tainted" : String |
2727
| CSharp7.cs:92:18:92:28 | call to method I | semmle.label | call to method I |
28-
| CSharp7.cs:92:20:92:21 | access to local variable t1 [Item1] : String | semmle.label | access to local variable t1 [Item1] : String |
28+
| CSharp7.cs:92:20:92:21 | access to local variable t1 [field Item1] : String | semmle.label | access to local variable t1 [field Item1] : String |
2929
| CSharp7.cs:92:20:92:27 | access to field Item1 : String | semmle.label | access to field Item1 : String |
3030
| CSharp7.cs:177:22:177:30 | "tainted" | semmle.label | "tainted" |
3131
| CSharp7.cs:177:22:177:30 | "tainted" : String | semmle.label | "tainted" : String |

csharp/ql/test/library-tests/dataflow/async/Async.expected

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ edges
44
| Async.cs:14:34:14:34 | x : String | Async.cs:16:16:16:16 | access to parameter x : String |
55
| Async.cs:16:16:16:16 | access to parameter x : String | Async.cs:11:14:11:26 | call to method Return |
66
| Async.cs:19:41:19:45 | input : String | Async.cs:21:32:21:36 | access to parameter input : String |
7-
| Async.cs:21:20:21:37 | call to method ReturnAwait [Result] : String | Async.cs:21:14:21:37 | await ... |
8-
| Async.cs:21:32:21:36 | access to parameter input : String | Async.cs:21:20:21:37 | call to method ReturnAwait [Result] : String |
7+
| Async.cs:21:20:21:37 | call to method ReturnAwait [property Result] : String | Async.cs:21:14:21:37 | await ... |
8+
| Async.cs:21:32:21:36 | access to parameter input : String | Async.cs:21:20:21:37 | call to method ReturnAwait [property Result] : String |
99
| Async.cs:24:41:24:45 | input : String | Async.cs:26:35:26:39 | access to parameter input : String |
1010
| Async.cs:26:17:26:40 | await ... : String | Async.cs:27:14:27:14 | access to local variable x |
11-
| Async.cs:26:23:26:40 | call to method ReturnAwait [Result] : String | Async.cs:26:17:26:40 | await ... : String |
12-
| Async.cs:26:35:26:39 | access to parameter input : String | Async.cs:26:23:26:40 | call to method ReturnAwait [Result] : String |
11+
| Async.cs:26:23:26:40 | call to method ReturnAwait [property Result] : String | Async.cs:26:17:26:40 | await ... : String |
12+
| Async.cs:26:35:26:39 | access to parameter input : String | Async.cs:26:23:26:40 | call to method ReturnAwait [property Result] : String |
1313
| Async.cs:30:35:30:39 | input : String | Async.cs:32:27:32:31 | access to parameter input : String |
14-
| Async.cs:32:14:32:32 | call to method ReturnAwait2 [Result] : String | Async.cs:32:14:32:39 | access to property Result |
15-
| Async.cs:32:27:32:31 | access to parameter input : String | Async.cs:32:14:32:32 | call to method ReturnAwait2 [Result] : String |
14+
| Async.cs:32:14:32:32 | call to method ReturnAwait2 [property Result] : String | Async.cs:32:14:32:39 | access to property Result |
15+
| Async.cs:32:27:32:31 | access to parameter input : String | Async.cs:32:14:32:32 | call to method ReturnAwait2 [property Result] : String |
1616
| Async.cs:35:51:35:51 | x : String | Async.cs:38:16:38:16 | access to parameter x : String |
17-
| Async.cs:38:16:38:16 | access to parameter x : String | Async.cs:21:20:21:37 | call to method ReturnAwait [Result] : String |
18-
| Async.cs:38:16:38:16 | access to parameter x : String | Async.cs:26:23:26:40 | call to method ReturnAwait [Result] : String |
17+
| Async.cs:38:16:38:16 | access to parameter x : String | Async.cs:21:20:21:37 | call to method ReturnAwait [property Result] : String |
18+
| Async.cs:38:16:38:16 | access to parameter x : String | Async.cs:26:23:26:40 | call to method ReturnAwait [property Result] : String |
1919
| Async.cs:41:33:41:37 | input : String | Async.cs:43:25:43:29 | access to parameter input : String |
20-
| Async.cs:43:14:43:30 | call to method ReturnTask [Result] : String | Async.cs:43:14:43:37 | access to property Result |
21-
| Async.cs:43:25:43:29 | access to parameter input : String | Async.cs:43:14:43:30 | call to method ReturnTask [Result] : String |
20+
| Async.cs:43:14:43:30 | call to method ReturnTask [property Result] : String | Async.cs:43:14:43:37 | access to property Result |
21+
| Async.cs:43:25:43:29 | access to parameter input : String | Async.cs:43:14:43:30 | call to method ReturnTask [property Result] : String |
2222
| Async.cs:46:44:46:44 | x : String | Async.cs:48:32:48:32 | access to parameter x : String |
23-
| Async.cs:48:16:48:33 | call to method FromResult [Result] : String | Async.cs:43:14:43:30 | call to method ReturnTask [Result] : String |
24-
| Async.cs:48:32:48:32 | access to parameter x : String | Async.cs:48:16:48:33 | call to method FromResult [Result] : String |
23+
| Async.cs:48:16:48:33 | call to method FromResult [property Result] : String | Async.cs:43:14:43:30 | call to method ReturnTask [property Result] : String |
24+
| Async.cs:48:32:48:32 | access to parameter x : String | Async.cs:48:16:48:33 | call to method FromResult [property Result] : String |
2525
| Async.cs:51:52:51:52 | x : String | Async.cs:51:58:51:58 | access to parameter x : String |
26-
| Async.cs:51:58:51:58 | access to parameter x : String | Async.cs:32:14:32:32 | call to method ReturnAwait2 [Result] : String |
26+
| Async.cs:51:58:51:58 | access to parameter x : String | Async.cs:32:14:32:32 | call to method ReturnAwait2 [property Result] : String |
2727
nodes
2828
| Async.cs:9:37:9:41 | input : String | semmle.label | input : String |
2929
| Async.cs:11:14:11:26 | call to method Return | semmle.label | call to method Return |
@@ -32,25 +32,25 @@ nodes
3232
| Async.cs:16:16:16:16 | access to parameter x : String | semmle.label | access to parameter x : String |
3333
| Async.cs:19:41:19:45 | input : String | semmle.label | input : String |
3434
| Async.cs:21:14:21:37 | await ... | semmle.label | await ... |
35-
| Async.cs:21:20:21:37 | call to method ReturnAwait [Result] : String | semmle.label | call to method ReturnAwait [Result] : String |
35+
| Async.cs:21:20:21:37 | call to method ReturnAwait [property Result] : String | semmle.label | call to method ReturnAwait [property Result] : String |
3636
| Async.cs:21:32:21:36 | access to parameter input : String | semmle.label | access to parameter input : String |
3737
| Async.cs:24:41:24:45 | input : String | semmle.label | input : String |
3838
| Async.cs:26:17:26:40 | await ... : String | semmle.label | await ... : String |
39-
| Async.cs:26:23:26:40 | call to method ReturnAwait [Result] : String | semmle.label | call to method ReturnAwait [Result] : String |
39+
| Async.cs:26:23:26:40 | call to method ReturnAwait [property Result] : String | semmle.label | call to method ReturnAwait [property Result] : String |
4040
| Async.cs:26:35:26:39 | access to parameter input : String | semmle.label | access to parameter input : String |
4141
| Async.cs:27:14:27:14 | access to local variable x | semmle.label | access to local variable x |
4242
| Async.cs:30:35:30:39 | input : String | semmle.label | input : String |
43-
| Async.cs:32:14:32:32 | call to method ReturnAwait2 [Result] : String | semmle.label | call to method ReturnAwait2 [Result] : String |
43+
| Async.cs:32:14:32:32 | call to method ReturnAwait2 [property Result] : String | semmle.label | call to method ReturnAwait2 [property Result] : String |
4444
| Async.cs:32:14:32:39 | access to property Result | semmle.label | access to property Result |
4545
| Async.cs:32:27:32:31 | access to parameter input : String | semmle.label | access to parameter input : String |
4646
| Async.cs:35:51:35:51 | x : String | semmle.label | x : String |
4747
| Async.cs:38:16:38:16 | access to parameter x : String | semmle.label | access to parameter x : String |
4848
| Async.cs:41:33:41:37 | input : String | semmle.label | input : String |
49-
| Async.cs:43:14:43:30 | call to method ReturnTask [Result] : String | semmle.label | call to method ReturnTask [Result] : String |
49+
| Async.cs:43:14:43:30 | call to method ReturnTask [property Result] : String | semmle.label | call to method ReturnTask [property Result] : String |
5050
| Async.cs:43:14:43:37 | access to property Result | semmle.label | access to property Result |
5151
| Async.cs:43:25:43:29 | access to parameter input : String | semmle.label | access to parameter input : String |
5252
| Async.cs:46:44:46:44 | x : String | semmle.label | x : String |
53-
| Async.cs:48:16:48:33 | call to method FromResult [Result] : String | semmle.label | call to method FromResult [Result] : String |
53+
| Async.cs:48:16:48:33 | call to method FromResult [property Result] : String | semmle.label | call to method FromResult [property Result] : String |
5454
| Async.cs:48:32:48:32 | access to parameter x : String | semmle.label | access to parameter x : String |
5555
| Async.cs:51:52:51:52 | x : String | semmle.label | x : String |
5656
| Async.cs:51:58:51:58 | access to parameter x : String | semmle.label | access to parameter x : String |

0 commit comments

Comments
 (0)