Skip to content

Commit 59c7907

Browse files
authored
Merge pull request #4207 from RasmusWL/python-typetracker-small-fixes
Python: Small fixes for TypeTracker
2 parents fd715a5 + 6aae757 commit 59c7907

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

python/ql/src/experimental/dataflow/TypeTracker.qll

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** Step Summaries and Type Tracking */
22

3-
import python
4-
import internal.DataFlowPublic
5-
import internal.DataFlowPrivate
3+
private import python
4+
private import internal.DataFlowPublic
5+
private import internal.DataFlowPrivate
66

77
/** Any string that may appear as the name of an attribute or access path. */
88
class AttributeName extends string {
@@ -144,7 +144,7 @@ private newtype TTypeTracker = MkTypeTracker(Boolean hasCall, OptionalAttributeN
144144
* It is recommended that all uses of this type are written in the following form,
145145
* for tracking some type `myType`:
146146
* ```
147-
* Node myType(DataFlow::TypeTracker t) {
147+
* DataFlow::Node myType(DataFlow::TypeTracker t) {
148148
* t.start() and
149149
* result = < source of myType >
150150
* or
@@ -153,7 +153,7 @@ private newtype TTypeTracker = MkTypeTracker(Boolean hasCall, OptionalAttributeN
153153
* )
154154
* }
155155
*
156-
* DataFlow::SourceNode myType() { result = myType(DataFlow::TypeTracker::end()) }
156+
* DataFlow::Node myType() { result = myType(DataFlow::TypeTracker::end()) }
157157
* ```
158158
*
159159
* Instead of `result = myType(t2).track(t2, t)`, you can also use the equivalent
@@ -280,3 +280,10 @@ class TypeTracker extends TTypeTracker {
280280
result = this
281281
}
282282
}
283+
284+
module TypeTracker {
285+
/**
286+
* Gets a valid end point of type tracking.
287+
*/
288+
TypeTracker end() { result.end() }
289+
}

python/ql/test/experimental/dataflow/typetracking/tracked.ql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import python
2+
import experimental.dataflow.DataFlow
23
import experimental.dataflow.TypeTracker
34
import TestUtilities.InlineExpectationsTest
45

5-
Node tracked(TypeTracker t) {
6+
DataFlow::Node tracked(TypeTracker t) {
67
t.start() and
78
result.asCfgNode() = any(NameNode n | n.getId() = "tracked")
89
or
@@ -15,7 +16,7 @@ class TrackedTest extends InlineExpectationsTest {
1516
override string getARelevantTag() { result = "tracked" }
1617

1718
override predicate hasActualResult(Location location, string element, string tag, string value) {
18-
exists(Node e, TypeTracker t |
19+
exists(DataFlow::Node e, TypeTracker t |
1920
e = tracked(t) and
2021
tag = "tracked" and
2122
location = e.getLocation() and
@@ -25,14 +26,14 @@ class TrackedTest extends InlineExpectationsTest {
2526
}
2627
}
2728

28-
Node int_type(TypeTracker t) {
29+
DataFlow::Node int_type(TypeTracker t) {
2930
t.start() and
3031
result.asCfgNode() = any(CallNode c | c.getFunction().(NameNode).getId() = "int")
3132
or
3233
exists(TypeTracker t2 | result = int_type(t2).track(t2, t))
3334
}
3435

35-
Node string_type(TypeTracker t) {
36+
DataFlow::Node string_type(TypeTracker t) {
3637
t.start() and
3738
result.asCfgNode() = any(CallNode c | c.getFunction().(NameNode).getId() = "str")
3839
or
@@ -45,7 +46,7 @@ class TrackedIntTest extends InlineExpectationsTest {
4546
override string getARelevantTag() { result = "int" }
4647

4748
override predicate hasActualResult(Location location, string element, string tag, string value) {
48-
exists(Node e, TypeTracker t |
49+
exists(DataFlow::Node e, TypeTracker t |
4950
e = int_type(t) and
5051
tag = "int" and
5152
location = e.getLocation() and
@@ -61,7 +62,7 @@ class TrackedStringTest extends InlineExpectationsTest {
6162
override string getARelevantTag() { result = "str" }
6263

6364
override predicate hasActualResult(Location location, string element, string tag, string value) {
64-
exists(Node e, TypeTracker t |
65+
exists(DataFlow::Node e, TypeTracker t |
6566
e = string_type(t) and
6667
tag = "str" and
6768
location = e.getLocation() and

0 commit comments

Comments
 (0)