Skip to content

Commit dd23e12

Browse files
committed
Rename TypeTrackerContentSet -> TypeTrackerContent
1 parent 6abf77d commit dd23e12

File tree

3 files changed

+55
-60
lines changed

3 files changed

+55
-60
lines changed

ruby/ql/lib/codeql/ruby/ApiGraphs.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ module API {
520520
read = c.getExpr()
521521
)
522522
or
523-
exists(TypeTrackerSpecific::TypeTrackerContentSet c |
523+
exists(TypeTrackerSpecific::TypeTrackerContent c |
524524
TypeTrackerSpecific::basicLoadStep(node, ref, c) and
525525
lbl = Label::content(c.getAStoreContent())
526526
)
@@ -532,7 +532,7 @@ module API {
532532
* from a def node that is reachable from `node`.
533533
*/
534534
private predicate defStep(Label::ApiLabel lbl, DataFlow::Node node, DataFlow::Node rhs) {
535-
exists(TypeTrackerSpecific::TypeTrackerContentSet c |
535+
exists(TypeTrackerSpecific::TypeTrackerContent c |
536536
TypeTrackerSpecific::basicStoreStep(rhs, node, c) and
537537
lbl = Label::content(c.getAStoreContent())
538538
)

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

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ private module Cached {
1212
LevelStep() or
1313
CallStep() or
1414
ReturnStep() or
15-
StoreStep(TypeTrackerContentSet contents) or
16-
LoadStep(TypeTrackerContentSet contents) or
15+
StoreStep(TypeTrackerContent content) or
16+
LoadStep(TypeTrackerContent content) or
1717
JumpStep()
1818

1919
pragma[nomagic]
2020
private TypeTracker noContentTypeTracker(boolean hasCall) {
21-
result = MkTypeTracker(hasCall, noContentSet())
21+
result = MkTypeTracker(hasCall, noContent())
2222
}
2323

2424
/** Gets the summary resulting from appending `step` to type-tracking summary `tt`. */
2525
cached
2626
TypeTracker append(TypeTracker tt, StepSummary step) {
27-
exists(Boolean hasCall, OptionalTypeTrackerContentSet currentContents |
27+
exists(Boolean hasCall, OptionalTypeTrackerContent currentContents |
2828
tt = MkTypeTracker(hasCall, currentContents)
2929
|
3030
step = LevelStep() and result = tt
@@ -37,8 +37,8 @@ private module Cached {
3737
result = MkTypeTracker(false, currentContents)
3838
)
3939
or
40-
exists(TypeTrackerContentSet storeContents, boolean hasCall |
41-
exists(TypeTrackerContentSet loadContents |
40+
exists(TypeTrackerContent storeContents, boolean hasCall |
41+
exists(TypeTrackerContent loadContents |
4242
step = LoadStep(pragma[only_bind_into](loadContents)) and
4343
tt = MkTypeTracker(hasCall, storeContents) and
4444
compatibleContents(storeContents, loadContents) and
@@ -53,27 +53,27 @@ private module Cached {
5353

5454
pragma[nomagic]
5555
private TypeBackTracker noContentTypeBackTracker(boolean hasReturn) {
56-
result = MkTypeBackTracker(hasReturn, noContentSet())
56+
result = MkTypeBackTracker(hasReturn, noContent())
5757
}
5858

5959
/** Gets the summary resulting from prepending `step` to this type-tracking summary. */
6060
cached
6161
TypeBackTracker prepend(TypeBackTracker tbt, StepSummary step) {
62-
exists(Boolean hasReturn, OptionalTypeTrackerContentSet contents |
63-
tbt = MkTypeBackTracker(hasReturn, contents)
62+
exists(Boolean hasReturn, OptionalTypeTrackerContent content |
63+
tbt = MkTypeBackTracker(hasReturn, content)
6464
|
6565
step = LevelStep() and result = tbt
6666
or
6767
step = CallStep() and hasReturn = false and result = tbt
6868
or
69-
step = ReturnStep() and result = MkTypeBackTracker(true, contents)
69+
step = ReturnStep() and result = MkTypeBackTracker(true, content)
7070
or
7171
step = JumpStep() and
72-
result = MkTypeBackTracker(false, contents)
72+
result = MkTypeBackTracker(false, content)
7373
)
7474
or
75-
exists(TypeTrackerContentSet loadContents, boolean hasReturn |
76-
exists(TypeTrackerContentSet storeContents |
75+
exists(TypeTrackerContent loadContents, boolean hasReturn |
76+
exists(TypeTrackerContent storeContents |
7777
step = StoreStep(pragma[only_bind_into](storeContents)) and
7878
tbt = MkTypeBackTracker(hasReturn, loadContents) and
7979
compatibleContents(storeContents, loadContents) and
@@ -123,11 +123,9 @@ class StepSummary extends TStepSummary {
123123
or
124124
this instanceof ReturnStep and result = "return"
125125
or
126-
exists(TypeTrackerContentSet contents | this = StoreStep(contents) |
127-
result = "store " + contents
128-
)
126+
exists(TypeTrackerContent content | this = StoreStep(content) | result = "store " + content)
129127
or
130-
exists(TypeTrackerContentSet contents | this = LoadStep(contents) | result = "load " + contents)
128+
exists(TypeTrackerContent content | this = LoadStep(content) | result = "load " + content)
131129
or
132130
this instanceof JumpStep and result = "jump"
133131
}
@@ -141,11 +139,11 @@ private predicate smallstepNoCall(Node nodeFrom, TypeTrackingNode nodeTo, StepSu
141139
levelStep(nodeFrom, nodeTo) and
142140
summary = LevelStep()
143141
or
144-
exists(TypeTrackerContentSet contents |
145-
StepSummary::localSourceStoreStep(nodeFrom, nodeTo, contents) and
146-
summary = StoreStep(contents)
142+
exists(TypeTrackerContent content |
143+
StepSummary::localSourceStoreStep(nodeFrom, nodeTo, content) and
144+
summary = StoreStep(content)
147145
or
148-
basicLoadStep(nodeFrom, nodeTo, contents) and summary = LoadStep(contents)
146+
basicLoadStep(nodeFrom, nodeTo, content) and summary = LoadStep(content)
149147
)
150148
}
151149

@@ -191,7 +189,7 @@ module StepSummary {
191189
}
192190

193191
/**
194-
* Holds if `nodeFrom` is being written to the `contents` of the object in `nodeTo`.
192+
* Holds if `nodeFrom` is being written to the `content` of the object in `nodeTo`.
195193
*
196194
* Note that `nodeTo` will always be a local source node that flows to the place where the content
197195
* is written in `basicStoreStep`. This may lead to the flow of information going "back in time"
@@ -210,20 +208,17 @@ module StepSummary {
210208
* def bar(x):
211209
* z = x.attr
212210
* ```
213-
* for the attribute write `x.attr = y`, we will have `contents` being the literal string `"attr"`,
211+
* for the attribute write `x.attr = y`, we will have `content` being the literal string `"attr"`,
214212
* `nodeFrom` will be `y`, and `nodeTo` will be the object `Foo()` created on the first line of the
215213
* function. This means we will track the fact that `x.attr` can have the type of `y` into the
216214
* assignment to `z` inside `bar`, even though this attribute write happens _after_ `bar` is called.
217215
*/
218-
predicate localSourceStoreStep(
219-
Node nodeFrom, TypeTrackingNode nodeTo, TypeTrackerContentSet contents
220-
) {
221-
exists(Node obj | nodeTo.flowsTo(obj) and basicStoreStep(nodeFrom, obj, contents))
216+
predicate localSourceStoreStep(Node nodeFrom, TypeTrackingNode nodeTo, TypeTrackerContent content) {
217+
exists(Node obj | nodeTo.flowsTo(obj) and basicStoreStep(nodeFrom, obj, content))
222218
}
223219
}
224220

225-
private newtype TTypeTracker =
226-
MkTypeTracker(Boolean hasCall, OptionalTypeTrackerContentSet contents)
221+
private newtype TTypeTracker = MkTypeTracker(Boolean hasCall, OptionalTypeTrackerContent content)
227222

228223
/**
229224
* A summary of the steps needed to track a value to a given dataflow node.
@@ -254,9 +249,9 @@ private newtype TTypeTracker =
254249
*/
255250
class TypeTracker extends TTypeTracker {
256251
Boolean hasCall;
257-
OptionalTypeTrackerContentSet contents;
252+
OptionalTypeTrackerContent content;
258253

259-
TypeTracker() { this = MkTypeTracker(hasCall, contents) }
254+
TypeTracker() { this = MkTypeTracker(hasCall, content) }
260255

261256
/** Gets the summary resulting from appending `step` to this type-tracking summary. */
262257
TypeTracker append(StepSummary step) { result = append(this, step) }
@@ -266,8 +261,8 @@ class TypeTracker extends TTypeTracker {
266261
exists(string withCall, string withContent |
267262
(if hasCall = true then withCall = "with" else withCall = "without") and
268263
(
269-
if contents != noContentSet()
270-
then withContent = " with content " + contents
264+
if content != noContent()
265+
then withContent = " with content " + content
271266
else withContent = ""
272267
) and
273268
result = "type tracker " + withCall + " call steps" + withContent
@@ -277,26 +272,26 @@ class TypeTracker extends TTypeTracker {
277272
/**
278273
* Holds if this is the starting point of type tracking.
279274
*/
280-
predicate start() { hasCall = false and contents = noContentSet() }
275+
predicate start() { hasCall = false and content = noContent() }
281276

282277
/**
283278
* Holds if this is the starting point of type tracking, and the value starts in the content named `contentName`.
284279
* The type tracking only ends after the content has been loaded.
285280
*/
286-
predicate startInContent(TypeTrackerContentSet contentName) {
287-
hasCall = false and contents = contentName
281+
predicate startInContent(TypeTrackerContent contentName) {
282+
hasCall = false and content = contentName
288283
}
289284

290285
/**
291286
* Holds if this is the starting point of type tracking
292287
* when tracking a parameter into a call, but not out of it.
293288
*/
294-
predicate call() { hasCall = true and contents = noContentSet() }
289+
predicate call() { hasCall = true and content = noContent() }
295290

296291
/**
297292
* Holds if this is the end point of type tracking.
298293
*/
299-
predicate end() { contents = noContentSet() }
294+
predicate end() { content = noContent() }
300295

301296
/**
302297
* INTERNAL. DO NOT USE.
@@ -310,15 +305,15 @@ class TypeTracker extends TTypeTracker {
310305
*
311306
* Gets the content associated with this type tracker.
312307
*/
313-
OptionalTypeTrackerContentSet getContent() { result = contents }
308+
OptionalTypeTrackerContent getContent() { result = content }
314309

315310
/**
316311
* Gets a type tracker that starts where this one has left off to allow continued
317312
* tracking.
318313
*
319314
* This predicate is only defined if the type is not associated to a piece of content.
320315
*/
321-
TypeTracker continue() { contents = noContentSet() and result = this }
316+
TypeTracker continue() { content = noContent() and result = this }
322317

323318
/**
324319
* Gets the summary that corresponds to having taken a forwards
@@ -377,7 +372,7 @@ module TypeTracker {
377372
}
378373

379374
private newtype TTypeBackTracker =
380-
MkTypeBackTracker(Boolean hasReturn, OptionalTypeTrackerContentSet contents)
375+
MkTypeBackTracker(Boolean hasReturn, OptionalTypeTrackerContent content)
381376

382377
/**
383378
* A summary of the steps needed to back-track a use of a value to a given dataflow node.
@@ -411,9 +406,9 @@ private newtype TTypeBackTracker =
411406
*/
412407
class TypeBackTracker extends TTypeBackTracker {
413408
Boolean hasReturn;
414-
OptionalTypeTrackerContentSet contents;
409+
OptionalTypeTrackerContent content;
415410

416-
TypeBackTracker() { this = MkTypeBackTracker(hasReturn, contents) }
411+
TypeBackTracker() { this = MkTypeBackTracker(hasReturn, content) }
417412

418413
/** Gets the summary resulting from prepending `step` to this type-tracking summary. */
419414
TypeBackTracker prepend(StepSummary step) { result = prepend(this, step) }
@@ -423,8 +418,8 @@ class TypeBackTracker extends TTypeBackTracker {
423418
exists(string withReturn, string withContent |
424419
(if hasReturn = true then withReturn = "with" else withReturn = "without") and
425420
(
426-
if contents != noContentSet()
427-
then withContent = " with content " + contents
421+
if content != noContent()
422+
then withContent = " with content " + content
428423
else withContent = ""
429424
) and
430425
result = "type back-tracker " + withReturn + " return steps" + withContent
@@ -434,12 +429,12 @@ class TypeBackTracker extends TTypeBackTracker {
434429
/**
435430
* Holds if this is the starting point of type tracking.
436431
*/
437-
predicate start() { hasReturn = false and contents = noContentSet() }
432+
predicate start() { hasReturn = false and content = noContent() }
438433

439434
/**
440435
* Holds if this is the end point of type tracking.
441436
*/
442-
predicate end() { contents = noContentSet() }
437+
predicate end() { content = noContent() }
443438

444439
/**
445440
* INTERNAL. DO NOT USE.
@@ -454,7 +449,7 @@ class TypeBackTracker extends TTypeBackTracker {
454449
*
455450
* This predicate is only defined if the type has not been tracked into a piece of content.
456451
*/
457-
TypeBackTracker continue() { contents = noContentSet() and result = this }
452+
TypeBackTracker continue() { content = noContent() and result = this }
458453

459454
/**
460455
* Gets the summary that corresponds to having taken a backwards
@@ -511,7 +506,7 @@ class TypeBackTracker extends TTypeBackTracker {
511506
* also flow to `sink`.
512507
*/
513508
TypeTracker getACompatibleTypeTracker() {
514-
exists(boolean hasCall | result = MkTypeTracker(hasCall, contents) |
509+
exists(boolean hasCall | result = MkTypeTracker(hasCall, content) |
515510
hasCall = false or this.hasReturn() = false
516511
)
517512
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ class Node = DataFlowPublic::Node;
1515

1616
class TypeTrackingNode = DataFlowPublic::LocalSourceNode;
1717

18-
class TypeTrackerContentSet = DataFlowPublic::ContentSet;
18+
class TypeTrackerContent = DataFlowPublic::ContentSet;
1919

20-
class OptionalTypeTrackerContentSet = DataFlowPublic::OptionalContentSet;
20+
class OptionalTypeTrackerContent = DataFlowPublic::OptionalContentSet;
2121

2222
/**
2323
* Holds if a value stored with `storeContents` can be read back with `loadContents`.
2424
*/
2525
pragma[inline]
26-
predicate compatibleContents(TypeTrackerContentSet storeContents, TypeTrackerContentSet loadContents) {
26+
predicate compatibleContents(TypeTrackerContent storeContents, TypeTrackerContent loadContents) {
2727
storeContents.getAStoreContent() = loadContents.getAReadContent()
2828
}
2929

3030
/** Gets the "no content set" value to use for a type tracker not inside any content. */
31-
OptionalTypeTrackerContentSet noContentSet() { result.isNoContentSet() }
31+
OptionalTypeTrackerContent noContent() { result.isNoContentSet() }
3232

3333
/** Holds if there is a simple local flow step from `nodeFrom` to `nodeTo` */
3434
predicate simpleLocalFlowStep = DataFlowPrivate::localFlowStepTypeTracker/2;
@@ -156,7 +156,7 @@ predicate returnStep(Node nodeFrom, Node nodeTo) {
156156
* to `z` inside `bar`, even though this content write happens _after_ `bar` is
157157
* called.
158158
*/
159-
predicate basicStoreStep(Node nodeFrom, Node nodeTo, TypeTrackerContentSet contents) {
159+
predicate basicStoreStep(Node nodeFrom, Node nodeTo, TypeTrackerContent contents) {
160160
postUpdateStoreStep(nodeFrom, nodeTo, contents)
161161
or
162162
exists(
@@ -174,7 +174,7 @@ predicate basicStoreStep(Node nodeFrom, Node nodeTo, TypeTrackerContentSet conte
174174
* Holds if a store step `nodeFrom -> nodeTo` with `contents` exists, where the destination node
175175
* is a post-update node that should be treated as a local source node.
176176
*/
177-
predicate postUpdateStoreStep(Node nodeFrom, Node nodeTo, TypeTrackerContentSet contents) {
177+
predicate postUpdateStoreStep(Node nodeFrom, Node nodeTo, TypeTrackerContent contents) {
178178
// TODO: support SetterMethodCall inside TuplePattern
179179
exists(ExprNodes::MethodCallCfgNode call |
180180
contents
@@ -191,7 +191,7 @@ predicate postUpdateStoreStep(Node nodeFrom, Node nodeTo, TypeTrackerContentSet
191191
/**
192192
* Holds if `nodeTo` is the result of accessing the `content` content of `nodeFrom`.
193193
*/
194-
predicate basicLoadStep(Node nodeFrom, Node nodeTo, TypeTrackerContentSet contents) {
194+
predicate basicLoadStep(Node nodeFrom, Node nodeTo, TypeTrackerContent contents) {
195195
exists(ExprNodes::MethodCallCfgNode call |
196196
call.getExpr().getNumberOfArguments() = 0 and
197197
contents.isSingleton(DataFlowPublic::Content::getAttributeName(call.getExpr().getMethodName())) and
@@ -220,7 +220,7 @@ class Boolean extends boolean {
220220
private import SummaryComponentStack
221221

222222
private predicate hasStoreSummary(
223-
SummarizedCallable callable, TypeTrackerContentSet contents, SummaryComponent input,
223+
SummarizedCallable callable, TypeTrackerContent contents, SummaryComponent input,
224224
SummaryComponent output
225225
) {
226226
callable
@@ -229,7 +229,7 @@ private predicate hasStoreSummary(
229229
}
230230

231231
private predicate hasLoadSummary(
232-
SummarizedCallable callable, TypeTrackerContentSet contents, SummaryComponent input,
232+
SummarizedCallable callable, TypeTrackerContent contents, SummaryComponent input,
233233
SummaryComponent output
234234
) {
235235
callable

0 commit comments

Comments
 (0)