Skip to content

Commit c1db0a9

Browse files
authored
Merge pull request github#8317 from hvitved/typetracker/jump-step
Ruby/Python: Clear call contexts after jump steps in type tracking
2 parents 173f45f + 9d6d479 commit c1db0a9

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/TypeTracker.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ private module Cached {
3434
CallStep() or
3535
ReturnStep() or
3636
StoreStep(ContentName content) or
37-
LoadStep(ContentName content)
37+
LoadStep(ContentName content) or
38+
JumpStep()
3839

3940
/** Gets the summary resulting from appending `step` to type-tracking summary `tt`. */
4041
cached
@@ -49,6 +50,9 @@ private module Cached {
4950
step = LoadStep(content) and result = MkTypeTracker(hasCall, "")
5051
or
5152
exists(string p | step = StoreStep(p) and content = "" and result = MkTypeTracker(hasCall, p))
53+
or
54+
step = JumpStep() and
55+
result = MkTypeTracker(false, content)
5256
)
5357
}
5458

@@ -67,6 +71,9 @@ private module Cached {
6771
)
6872
or
6973
step = StoreStep(content) and result = MkTypeBackTracker(hasReturn, "")
74+
or
75+
step = JumpStep() and
76+
result = MkTypeBackTracker(false, content)
7077
)
7178
}
7279

@@ -110,12 +117,17 @@ class StepSummary extends TStepSummary {
110117
exists(string content | this = StoreStep(content) | result = "store " + content)
111118
or
112119
exists(string content | this = LoadStep(content) | result = "load " + content)
120+
or
121+
this instanceof JumpStep and result = "jump"
113122
}
114123
}
115124

116125
pragma[noinline]
117126
private predicate smallstepNoCall(Node nodeFrom, TypeTrackingNode nodeTo, StepSummary summary) {
118127
jumpStep(nodeFrom, nodeTo) and
128+
summary = JumpStep()
129+
or
130+
levelStep(nodeFrom, nodeTo) and
119131
summary = LevelStep()
120132
or
121133
exists(string content |

python/ql/lib/semmle/python/dataflow/new/internal/TypeTrackerSpecific.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ predicate simpleLocalFlowStep = DataFlowPrivate::simpleLocalFlowStep/2;
1414

1515
predicate jumpStep = DataFlowPrivate::jumpStep/2;
1616

17+
/** Holds if there is a level step from `pred` to `succ`. */
18+
predicate levelStep(Node pred, Node succ) { none() }
19+
1720
/**
1821
* Gets the name of a possible piece of content. For Python, this is currently only attribute names,
1922
* using the name of the attribute for the corresponding content.

ruby/ql/lib/codeql/ruby/typetracking/TypeTracker.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ private module Cached {
3434
CallStep() or
3535
ReturnStep() or
3636
StoreStep(ContentName content) or
37-
LoadStep(ContentName content)
37+
LoadStep(ContentName content) or
38+
JumpStep()
3839

3940
/** Gets the summary resulting from appending `step` to type-tracking summary `tt`. */
4041
cached
@@ -49,6 +50,9 @@ private module Cached {
4950
step = LoadStep(content) and result = MkTypeTracker(hasCall, "")
5051
or
5152
exists(string p | step = StoreStep(p) and content = "" and result = MkTypeTracker(hasCall, p))
53+
or
54+
step = JumpStep() and
55+
result = MkTypeTracker(false, content)
5256
)
5357
}
5458

@@ -67,6 +71,9 @@ private module Cached {
6771
)
6872
or
6973
step = StoreStep(content) and result = MkTypeBackTracker(hasReturn, "")
74+
or
75+
step = JumpStep() and
76+
result = MkTypeBackTracker(false, content)
7077
)
7178
}
7279

@@ -110,12 +117,17 @@ class StepSummary extends TStepSummary {
110117
exists(string content | this = StoreStep(content) | result = "store " + content)
111118
or
112119
exists(string content | this = LoadStep(content) | result = "load " + content)
120+
or
121+
this instanceof JumpStep and result = "jump"
113122
}
114123
}
115124

116125
pragma[noinline]
117126
private predicate smallstepNoCall(Node nodeFrom, TypeTrackingNode nodeTo, StepSummary summary) {
118127
jumpStep(nodeFrom, nodeTo) and
128+
summary = JumpStep()
129+
or
130+
levelStep(nodeFrom, nodeTo) and
119131
summary = LevelStep()
120132
or
121133
exists(string content |

ruby/ql/lib/codeql/ruby/typetracking/TypeTrackerSpecific.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ predicate simpleLocalFlowStep = DataFlowPrivate::localFlowStepTypeTracker/2;
1515

1616
predicate jumpStep = DataFlowPrivate::jumpStep/2;
1717

18+
/** Holds if there is a level step from `pred` to `succ`. */
19+
predicate levelStep(Node pred, Node succ) { none() }
20+
1821
/**
1922
* Gets the name of a possible piece of content. This will usually include things like
2023
*

0 commit comments

Comments
 (0)