Skip to content

Commit 1c4c058

Browse files
committed
Ruby: Restrict summaries and type trackers to relevant contents
1 parent 3af3772 commit 1c4c058

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ private module Cached {
1212
LevelStep() or
1313
CallStep() or
1414
ReturnStep() or
15-
StoreStep(TypeTrackerContent content) or
16-
LoadStep(TypeTrackerContent content) or
15+
StoreStep(TypeTrackerContent content) { basicStoreStep(_, _, content) } or
16+
LoadStep(TypeTrackerContent content) { basicLoadStep(_, _, content) } or
1717
JumpStep()
1818

1919
pragma[nomagic]
@@ -218,7 +218,10 @@ module StepSummary {
218218
}
219219
}
220220

221-
private newtype TTypeTracker = MkTypeTracker(Boolean hasCall, OptionalTypeTrackerContent content)
221+
private newtype TTypeTracker =
222+
MkTypeTracker(Boolean hasCall, OptionalTypeTrackerContent content) {
223+
content = noContent() or basicStoreStep(_, _, content)
224+
}
222225

223226
/**
224227
* A summary of the steps needed to track a value to a given dataflow node.
@@ -372,7 +375,9 @@ module TypeTracker {
372375
}
373376

374377
private newtype TTypeBackTracker =
375-
MkTypeBackTracker(Boolean hasReturn, OptionalTypeTrackerContent content)
378+
MkTypeBackTracker(Boolean hasReturn, OptionalTypeTrackerContent content) {
379+
content = noContent() or basicLoadStep(_, _, content)
380+
}
376381

377382
/**
378383
* A summary of the steps needed to back-track a use of a value to a given dataflow node.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ predicate returnStep(Node nodeFrom, Node nodeTo) {
167167
* to `z` inside `bar`, even though this content write happens _after_ `bar` is
168168
* called.
169169
*/
170-
predicate basicStoreStep(Node nodeFrom, Node nodeTo, TypeTrackerContent contents) {
170+
predicate basicStoreStep(Node nodeFrom, Node nodeTo, DataFlow::ContentSet contents) {
171171
postUpdateStoreStep(nodeFrom, nodeTo, contents)
172172
or
173173
exists(
@@ -185,7 +185,7 @@ predicate basicStoreStep(Node nodeFrom, Node nodeTo, TypeTrackerContent contents
185185
* Holds if a store step `nodeFrom -> nodeTo` with `contents` exists, where the destination node
186186
* is a post-update node that should be treated as a local source node.
187187
*/
188-
predicate postUpdateStoreStep(Node nodeFrom, Node nodeTo, TypeTrackerContent contents) {
188+
predicate postUpdateStoreStep(Node nodeFrom, Node nodeTo, DataFlow::ContentSet contents) {
189189
// TODO: support SetterMethodCall inside TuplePattern
190190
exists(ExprNodes::MethodCallCfgNode call |
191191
contents
@@ -202,7 +202,7 @@ predicate postUpdateStoreStep(Node nodeFrom, Node nodeTo, TypeTrackerContent con
202202
/**
203203
* Holds if `nodeTo` is the result of accessing the `content` content of `nodeFrom`.
204204
*/
205-
predicate basicLoadStep(Node nodeFrom, Node nodeTo, TypeTrackerContent contents) {
205+
predicate basicLoadStep(Node nodeFrom, Node nodeTo, DataFlow::ContentSet contents) {
206206
exists(ExprNodes::MethodCallCfgNode call |
207207
call.getExpr().getNumberOfArguments() = 0 and
208208
contents.isSingleton(DataFlowPublic::Content::getAttributeName(call.getExpr().getMethodName())) and
@@ -231,7 +231,7 @@ class Boolean extends boolean {
231231
private import SummaryComponentStack
232232

233233
private predicate hasStoreSummary(
234-
SummarizedCallable callable, TypeTrackerContent contents, SummaryComponent input,
234+
SummarizedCallable callable, DataFlow::ContentSet contents, SummaryComponent input,
235235
SummaryComponent output
236236
) {
237237
callable
@@ -240,7 +240,7 @@ private predicate hasStoreSummary(
240240
}
241241

242242
private predicate hasLoadSummary(
243-
SummarizedCallable callable, TypeTrackerContent contents, SummaryComponent input,
243+
SummarizedCallable callable, DataFlow::ContentSet contents, SummaryComponent input,
244244
SummaryComponent output
245245
) {
246246
callable

0 commit comments

Comments
 (0)