Skip to content

Commit 246d904

Browse files
authored
Merge pull request github#12948 from aschackmull/dataflow/pathnode-type-tostring
Dataflow: Add type to PathNode.toString.
2 parents f888382 + f685ae1 commit 246d904

File tree

33 files changed

+2443
-2251
lines changed

33 files changed

+2443
-2251
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,6 +3031,17 @@ module Impl<FullStateConfigSig Config> {
30313031
this instanceof PathNodeSinkGroup
30323032
}
30333033

3034+
private string ppType() {
3035+
this instanceof PathNodeSink and result = ""
3036+
or
3037+
this.(PathNodeMid).getAp() instanceof AccessPathNil and result = ""
3038+
or
3039+
exists(DataFlowType t | t = this.(PathNodeMid).getAp().getHead().getContainerType() |
3040+
// The `concat` becomes "" if `ppReprType` has no result.
3041+
result = concat(" : " + ppReprType(t))
3042+
)
3043+
}
3044+
30343045
private string ppAp() {
30353046
this instanceof PathNodeSink and result = ""
30363047
or
@@ -3046,14 +3057,14 @@ module Impl<FullStateConfigSig Config> {
30463057
}
30473058

30483059
/** Gets a textual representation of this element. */
3049-
string toString() { result = this.getNodeEx().toString() + this.ppAp() }
3060+
string toString() { result = this.getNodeEx().toString() + this.ppType() + this.ppAp() }
30503061

30513062
/**
30523063
* Gets a textual representation of this element, including a textual
30533064
* representation of the call context.
30543065
*/
30553066
string toStringWithContext() {
3056-
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
3067+
result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx()
30573068
}
30583069

30593070
/**
@@ -3998,14 +4009,14 @@ module Impl<FullStateConfigSig Config> {
39984009
*/
39994010
class PartialPathNode extends TPartialPathNode {
40004011
/** Gets a textual representation of this element. */
4001-
string toString() { result = this.getNodeEx().toString() + this.ppAp() }
4012+
string toString() { result = this.getNodeEx().toString() + this.ppType() + this.ppAp() }
40024013

40034014
/**
40044015
* Gets a textual representation of this element, including a textual
40054016
* representation of the call context.
40064017
*/
40074018
string toStringWithContext() {
4008-
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
4019+
result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx()
40094020
}
40104021

40114022
/**
@@ -4046,6 +4057,19 @@ module Impl<FullStateConfigSig Config> {
40464057
*/
40474058
int getSinkDistance() { result = distSink(this.getNodeEx().getEnclosingCallable()) }
40484059

4060+
private string ppType() {
4061+
this instanceof PartialPathNodeRev and result = ""
4062+
or
4063+
this.(PartialPathNodeFwd).getAp() instanceof PartialAccessPathNil and result = ""
4064+
or
4065+
exists(DataFlowType t |
4066+
t = this.(PartialPathNodeFwd).getAp().(PartialAccessPathCons).getType()
4067+
|
4068+
// The `concat` becomes "" if `ppReprType` has no result.
4069+
result = concat(" : " + ppReprType(t))
4070+
)
4071+
}
4072+
40494073
private string ppAp() {
40504074
exists(string s |
40514075
s = this.(PartialPathNodeFwd).getAp().toString() or

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl.qll

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,6 +3031,17 @@ module Impl<FullStateConfigSig Config> {
30313031
this instanceof PathNodeSinkGroup
30323032
}
30333033

3034+
private string ppType() {
3035+
this instanceof PathNodeSink and result = ""
3036+
or
3037+
this.(PathNodeMid).getAp() instanceof AccessPathNil and result = ""
3038+
or
3039+
exists(DataFlowType t | t = this.(PathNodeMid).getAp().getHead().getContainerType() |
3040+
// The `concat` becomes "" if `ppReprType` has no result.
3041+
result = concat(" : " + ppReprType(t))
3042+
)
3043+
}
3044+
30343045
private string ppAp() {
30353046
this instanceof PathNodeSink and result = ""
30363047
or
@@ -3046,14 +3057,14 @@ module Impl<FullStateConfigSig Config> {
30463057
}
30473058

30483059
/** Gets a textual representation of this element. */
3049-
string toString() { result = this.getNodeEx().toString() + this.ppAp() }
3060+
string toString() { result = this.getNodeEx().toString() + this.ppType() + this.ppAp() }
30503061

30513062
/**
30523063
* Gets a textual representation of this element, including a textual
30533064
* representation of the call context.
30543065
*/
30553066
string toStringWithContext() {
3056-
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
3067+
result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx()
30573068
}
30583069

30593070
/**
@@ -3998,14 +4009,14 @@ module Impl<FullStateConfigSig Config> {
39984009
*/
39994010
class PartialPathNode extends TPartialPathNode {
40004011
/** Gets a textual representation of this element. */
4001-
string toString() { result = this.getNodeEx().toString() + this.ppAp() }
4012+
string toString() { result = this.getNodeEx().toString() + this.ppType() + this.ppAp() }
40024013

40034014
/**
40044015
* Gets a textual representation of this element, including a textual
40054016
* representation of the call context.
40064017
*/
40074018
string toStringWithContext() {
4008-
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
4019+
result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx()
40094020
}
40104021

40114022
/**
@@ -4046,6 +4057,19 @@ module Impl<FullStateConfigSig Config> {
40464057
*/
40474058
int getSinkDistance() { result = distSink(this.getNodeEx().getEnclosingCallable()) }
40484059

4060+
private string ppType() {
4061+
this instanceof PartialPathNodeRev and result = ""
4062+
or
4063+
this.(PartialPathNodeFwd).getAp() instanceof PartialAccessPathNil and result = ""
4064+
or
4065+
exists(DataFlowType t |
4066+
t = this.(PartialPathNodeFwd).getAp().(PartialAccessPathCons).getType()
4067+
|
4068+
// The `concat` becomes "" if `ppReprType` has no result.
4069+
result = concat(" : " + ppReprType(t))
4070+
)
4071+
}
4072+
40494073
private string ppAp() {
40504074
exists(string s |
40514075
s = this.(PartialPathNodeFwd).getAp().toString() or

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowImpl.qll

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,6 +3031,17 @@ module Impl<FullStateConfigSig Config> {
30313031
this instanceof PathNodeSinkGroup
30323032
}
30333033

3034+
private string ppType() {
3035+
this instanceof PathNodeSink and result = ""
3036+
or
3037+
this.(PathNodeMid).getAp() instanceof AccessPathNil and result = ""
3038+
or
3039+
exists(DataFlowType t | t = this.(PathNodeMid).getAp().getHead().getContainerType() |
3040+
// The `concat` becomes "" if `ppReprType` has no result.
3041+
result = concat(" : " + ppReprType(t))
3042+
)
3043+
}
3044+
30343045
private string ppAp() {
30353046
this instanceof PathNodeSink and result = ""
30363047
or
@@ -3046,14 +3057,14 @@ module Impl<FullStateConfigSig Config> {
30463057
}
30473058

30483059
/** Gets a textual representation of this element. */
3049-
string toString() { result = this.getNodeEx().toString() + this.ppAp() }
3060+
string toString() { result = this.getNodeEx().toString() + this.ppType() + this.ppAp() }
30503061

30513062
/**
30523063
* Gets a textual representation of this element, including a textual
30533064
* representation of the call context.
30543065
*/
30553066
string toStringWithContext() {
3056-
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
3067+
result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx()
30573068
}
30583069

30593070
/**
@@ -3998,14 +4009,14 @@ module Impl<FullStateConfigSig Config> {
39984009
*/
39994010
class PartialPathNode extends TPartialPathNode {
40004011
/** Gets a textual representation of this element. */
4001-
string toString() { result = this.getNodeEx().toString() + this.ppAp() }
4012+
string toString() { result = this.getNodeEx().toString() + this.ppType() + this.ppAp() }
40024013

40034014
/**
40044015
* Gets a textual representation of this element, including a textual
40054016
* representation of the call context.
40064017
*/
40074018
string toStringWithContext() {
4008-
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
4019+
result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx()
40094020
}
40104021

40114022
/**
@@ -4046,6 +4057,19 @@ module Impl<FullStateConfigSig Config> {
40464057
*/
40474058
int getSinkDistance() { result = distSink(this.getNodeEx().getEnclosingCallable()) }
40484059

4060+
private string ppType() {
4061+
this instanceof PartialPathNodeRev and result = ""
4062+
or
4063+
this.(PartialPathNodeFwd).getAp() instanceof PartialAccessPathNil and result = ""
4064+
or
4065+
exists(DataFlowType t |
4066+
t = this.(PartialPathNodeFwd).getAp().(PartialAccessPathCons).getType()
4067+
|
4068+
// The `concat` becomes "" if `ppReprType` has no result.
4069+
result = concat(" : " + ppReprType(t))
4070+
)
4071+
}
4072+
40494073
private string ppAp() {
40504074
exists(string s |
40514075
s = this.(PartialPathNodeFwd).getAp().toString() or

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ edges
77
| CSharp7.cs:55:11:55:19 | "tainted" : String | CSharp7.cs:55:30:55:31 | SSA def(t4) : String |
88
| CSharp7.cs:55:30:55:31 | SSA def(t4) : String | CSharp7.cs:56:18:56:19 | access to local variable t4 |
99
| CSharp7.cs:80:21:80:21 | x : String | CSharp7.cs:82:20:82:20 | access to parameter x : String |
10-
| CSharp7.cs:82:16:82:24 | (..., ...) [field Item1] : String | CSharp7.cs:82:16:82:26 | access to field Item1 : String |
11-
| CSharp7.cs:82:20:82:20 | access to parameter x : String | CSharp7.cs:82:16:82:24 | (..., ...) [field Item1] : String |
12-
| CSharp7.cs:87:18:87:34 | (..., ...) [field Item1] : String | CSharp7.cs:90:20:90:21 | access to local variable t1 [field Item1] : String |
13-
| CSharp7.cs:87:19:87:27 | "tainted" : String | CSharp7.cs:87:18:87:34 | (..., ...) [field Item1] : String |
14-
| CSharp7.cs:90:20:90:21 | access to local variable t1 [field Item1] : String | CSharp7.cs:90:20:90:27 | access to field Item1 : String |
10+
| CSharp7.cs:82:16:82:24 | (..., ...) : ValueTuple<String,Int32> [field Item1] : String | CSharp7.cs:82:16:82:26 | access to field Item1 : String |
11+
| CSharp7.cs:82:20:82:20 | access to parameter x : String | CSharp7.cs:82:16:82:24 | (..., ...) : ValueTuple<String,Int32> [field Item1] : String |
12+
| CSharp7.cs:87:18:87:34 | (..., ...) : ValueTuple<String,String> [field Item1] : String | CSharp7.cs:90:20:90:21 | access to local variable t1 : ValueTuple<String,String> [field Item1] : String |
13+
| CSharp7.cs:87:19:87:27 | "tainted" : String | CSharp7.cs:87:18:87:34 | (..., ...) : ValueTuple<String,String> [field Item1] : String |
14+
| CSharp7.cs:90:20:90:21 | access to local variable t1 : ValueTuple<String,String> [field Item1] : String | CSharp7.cs:90:20:90:27 | access to field Item1 : String |
1515
| CSharp7.cs:90:20:90:27 | access to field Item1 : String | CSharp7.cs:80:21:80:21 | x : String |
1616
| CSharp7.cs:90:20:90:27 | access to field Item1 : String | CSharp7.cs:90:18:90:28 | call to method I |
1717
| CSharp7.cs:175:22:175:30 | "tainted" : String | CSharp7.cs:181:23:181:25 | access to local variable src : String |
@@ -33,13 +33,13 @@ nodes
3333
| CSharp7.cs:55:30:55:31 | SSA def(t4) : String | semmle.label | SSA def(t4) : String |
3434
| CSharp7.cs:56:18:56:19 | access to local variable t4 | semmle.label | access to local variable t4 |
3535
| CSharp7.cs:80:21:80:21 | x : String | semmle.label | x : String |
36-
| CSharp7.cs:82:16:82:24 | (..., ...) [field Item1] : String | semmle.label | (..., ...) [field Item1] : String |
36+
| CSharp7.cs:82:16:82:24 | (..., ...) : ValueTuple<String,Int32> [field Item1] : String | semmle.label | (..., ...) : ValueTuple<String,Int32> [field Item1] : String |
3737
| CSharp7.cs:82:16:82:26 | access to field Item1 : String | semmle.label | access to field Item1 : String |
3838
| CSharp7.cs:82:20:82:20 | access to parameter x : String | semmle.label | access to parameter x : String |
39-
| CSharp7.cs:87:18:87:34 | (..., ...) [field Item1] : String | semmle.label | (..., ...) [field Item1] : String |
39+
| CSharp7.cs:87:18:87:34 | (..., ...) : ValueTuple<String,String> [field Item1] : String | semmle.label | (..., ...) : ValueTuple<String,String> [field Item1] : String |
4040
| CSharp7.cs:87:19:87:27 | "tainted" : String | semmle.label | "tainted" : String |
4141
| CSharp7.cs:90:18:90:28 | call to method I | semmle.label | call to method I |
42-
| CSharp7.cs:90:20:90:21 | access to local variable t1 [field Item1] : String | semmle.label | access to local variable t1 [field Item1] : String |
42+
| CSharp7.cs:90:20:90:21 | access to local variable t1 : ValueTuple<String,String> [field Item1] : String | semmle.label | access to local variable t1 : ValueTuple<String,String> [field Item1] : String |
4343
| CSharp7.cs:90:20:90:27 | access to field Item1 : String | semmle.label | access to field Item1 : String |
4444
| CSharp7.cs:175:22:175:30 | "tainted" | semmle.label | "tainted" |
4545
| CSharp7.cs:175:22:175:30 | "tainted" : String | semmle.label | "tainted" : String |

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ edges
77
| CSharp7.cs:55:11:55:19 | "tainted" : String | CSharp7.cs:55:30:55:31 | SSA def(t4) : String |
88
| CSharp7.cs:55:30:55:31 | SSA def(t4) : String | CSharp7.cs:56:18:56:19 | access to local variable t4 |
99
| CSharp7.cs:80:21:80:21 | x : String | CSharp7.cs:82:20:82:20 | access to parameter x : String |
10-
| CSharp7.cs:82:16:82:24 | (..., ...) [field Item1] : String | CSharp7.cs:82:16:82:26 | access to field Item1 : String |
11-
| CSharp7.cs:82:20:82:20 | access to parameter x : String | CSharp7.cs:82:16:82:24 | (..., ...) [field Item1] : String |
12-
| CSharp7.cs:87:18:87:34 | (..., ...) [field Item1] : String | CSharp7.cs:90:20:90:21 | access to local variable t1 [field Item1] : String |
13-
| CSharp7.cs:87:19:87:27 | "tainted" : String | CSharp7.cs:87:18:87:34 | (..., ...) [field Item1] : String |
14-
| CSharp7.cs:90:20:90:21 | access to local variable t1 [field Item1] : String | CSharp7.cs:90:20:90:27 | access to field Item1 : String |
10+
| CSharp7.cs:82:16:82:24 | (..., ...) : ValueTuple<String,Int32> [field Item1] : String | CSharp7.cs:82:16:82:26 | access to field Item1 : String |
11+
| CSharp7.cs:82:20:82:20 | access to parameter x : String | CSharp7.cs:82:16:82:24 | (..., ...) : ValueTuple<String,Int32> [field Item1] : String |
12+
| CSharp7.cs:87:18:87:34 | (..., ...) : ValueTuple<String,String> [field Item1] : String | CSharp7.cs:90:20:90:21 | access to local variable t1 : ValueTuple<String,String> [field Item1] : String |
13+
| CSharp7.cs:87:19:87:27 | "tainted" : String | CSharp7.cs:87:18:87:34 | (..., ...) : ValueTuple<String,String> [field Item1] : String |
14+
| CSharp7.cs:90:20:90:21 | access to local variable t1 : ValueTuple<String,String> [field Item1] : String | CSharp7.cs:90:20:90:27 | access to field Item1 : String |
1515
| CSharp7.cs:90:20:90:27 | access to field Item1 : String | CSharp7.cs:80:21:80:21 | x : String |
1616
| CSharp7.cs:90:20:90:27 | access to field Item1 : String | CSharp7.cs:90:18:90:28 | call to method I |
1717
| CSharp7.cs:175:22:175:30 | "tainted" : String | CSharp7.cs:180:23:180:25 | access to local variable src : String |
@@ -40,13 +40,13 @@ nodes
4040
| CSharp7.cs:55:30:55:31 | SSA def(t4) : String | semmle.label | SSA def(t4) : String |
4141
| CSharp7.cs:56:18:56:19 | access to local variable t4 | semmle.label | access to local variable t4 |
4242
| CSharp7.cs:80:21:80:21 | x : String | semmle.label | x : String |
43-
| CSharp7.cs:82:16:82:24 | (..., ...) [field Item1] : String | semmle.label | (..., ...) [field Item1] : String |
43+
| CSharp7.cs:82:16:82:24 | (..., ...) : ValueTuple<String,Int32> [field Item1] : String | semmle.label | (..., ...) : ValueTuple<String,Int32> [field Item1] : String |
4444
| CSharp7.cs:82:16:82:26 | access to field Item1 : String | semmle.label | access to field Item1 : String |
4545
| CSharp7.cs:82:20:82:20 | access to parameter x : String | semmle.label | access to parameter x : String |
46-
| CSharp7.cs:87:18:87:34 | (..., ...) [field Item1] : String | semmle.label | (..., ...) [field Item1] : String |
46+
| CSharp7.cs:87:18:87:34 | (..., ...) : ValueTuple<String,String> [field Item1] : String | semmle.label | (..., ...) : ValueTuple<String,String> [field Item1] : String |
4747
| CSharp7.cs:87:19:87:27 | "tainted" : String | semmle.label | "tainted" : String |
4848
| CSharp7.cs:90:18:90:28 | call to method I | semmle.label | call to method I |
49-
| CSharp7.cs:90:20:90:21 | access to local variable t1 [field Item1] : String | semmle.label | access to local variable t1 [field Item1] : String |
49+
| CSharp7.cs:90:20:90:21 | access to local variable t1 : ValueTuple<String,String> [field Item1] : String | semmle.label | access to local variable t1 : ValueTuple<String,String> [field Item1] : String |
5050
| CSharp7.cs:90:20:90:27 | access to field Item1 : String | semmle.label | access to field Item1 : String |
5151
| CSharp7.cs:175:22:175:30 | "tainted" | semmle.label | "tainted" |
5252
| CSharp7.cs:175:22:175:30 | "tainted" : String | semmle.label | "tainted" : String |

0 commit comments

Comments
 (0)