Skip to content

Commit daf81ae

Browse files
committed
Address review comments
1 parent ab46c07 commit daf81ae

File tree

3 files changed

+67
-67
lines changed

3 files changed

+67
-67
lines changed

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPublic.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,14 @@ module Content {
257257

258258
/** A value in a pair with a known key. */
259259
class KnownPairValueContent extends PairValueContent, TKnownPairValueContent {
260-
private ConstantValue cv;
260+
private ConstantValue key;
261261

262-
KnownPairValueContent() { this = TKnownPairValueContent(cv) }
262+
KnownPairValueContent() { this = TKnownPairValueContent(key) }
263263

264264
/** Gets the index in the collection. */
265-
ConstantValue getIndex() { result = cv }
265+
ConstantValue getIndex() { result = key }
266266

267-
override string toString() { result = "pair " + cv }
267+
override string toString() { result = "pair " + key }
268268
}
269269

270270
/** A value in a pair with an unknown key. */

ruby/ql/lib/codeql/ruby/frameworks/core/Array.qll

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,17 @@ module Array {
183183

184184
/** A call to `[]` with a known index. */
185185
private class ElementReferenceReadKnownSummary extends ElementReferenceReadSummary {
186-
private ConstantValue cv;
186+
private ConstantValue index;
187187

188188
ElementReferenceReadKnownSummary() {
189-
this = methodName + "(" + cv.serialize() + ")" and
189+
this = methodName + "(" + index.serialize() + ")" and
190190
mc.getNumberOfArguments() = 1 and
191-
cv = DataFlow::Content::getKnownElementIndex(mc.getArgument(0)) and
192-
if methodName = "slice" then cv.isInt(_) else any()
191+
index = DataFlow::Content::getKnownElementIndex(mc.getArgument(0)) and
192+
if methodName = "slice" then index.isInt(_) else any()
193193
}
194194

195195
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
196-
input = "Argument[self].Element[?," + cv.serialize() + "]" and
196+
input = "Argument[self].Element[?," + index.serialize() + "]" and
197197
output = "ReturnValue" and
198198
preservesValue = true
199199
}
@@ -308,20 +308,20 @@ module Array {
308308

309309
/** A call to `[]=` with a known index. */
310310
private class ElementReferenceStoreKnownSummary extends ElementReferenceStoreSummary {
311-
private ConstantValue cv;
311+
private ConstantValue index;
312312

313313
ElementReferenceStoreKnownSummary() {
314314
mc.getNumberOfArguments() = 2 and
315-
cv = DataFlow::Content::getKnownElementIndex(mc.getArgument(0)) and
316-
this = "[" + cv.serialize() + "]="
315+
index = DataFlow::Content::getKnownElementIndex(mc.getArgument(0)) and
316+
this = "[" + index.serialize() + "]="
317317
}
318318

319319
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
320320
input = "Argument[1]" and
321-
output = "Argument[self].Element[" + cv.serialize() + "]" and
321+
output = "Argument[self].Element[" + index.serialize() + "]" and
322322
preservesValue = true
323323
or
324-
input = "Argument[self].WithoutElement[" + cv.serialize() + "]" and
324+
input = "Argument[self].WithoutElement[" + index.serialize() + "]" and
325325
output = "Argument[self]" and
326326
preservesValue = true
327327
}
@@ -392,16 +392,16 @@ module Array {
392392
}
393393

394394
private class AtKnownSummary extends AtSummary {
395-
private ConstantValue cv;
395+
private ConstantValue index;
396396

397397
AtKnownSummary() {
398-
this = "at(" + cv.serialize() + "]" and
398+
this = "at(" + index.serialize() + "]" and
399399
mc.getNumberOfArguments() = 1 and
400-
cv = DataFlow::Content::getKnownElementIndex(mc.getArgument(0))
400+
index = DataFlow::Content::getKnownElementIndex(mc.getArgument(0))
401401
}
402402

403403
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
404-
input = "Argument[self].Element[" + cv.serialize() + ",?]" and
404+
input = "Argument[self].Element[" + index.serialize() + ",?]" and
405405
output = "ReturnValue" and
406406
preservesValue = true
407407
}
@@ -537,33 +537,33 @@ module Array {
537537
}
538538

539539
private class DeleteKnownSummary extends DeleteSummary {
540-
private ConstantValue cv;
540+
private ConstantValue index;
541541

542542
DeleteKnownSummary() {
543-
this = "delete(" + cv.serialize() + ")" and
544-
mc.getArgument(0).getConstantValue() = cv
543+
this = "delete(" + index.serialize() + ")" and
544+
mc.getArgument(0).getConstantValue() = index
545545
}
546546

547547
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
548548
super.propagatesFlowExt(input, output, preservesValue)
549549
or
550550
(
551551
(
552-
if cv.isInt(_)
552+
if index.isInt(_)
553553
then
554554
// array indices may get shifted
555-
input = "Argument[self].WithoutElement[" + cv.serialize() + "].Element[0..]" and
555+
input = "Argument[self].WithoutElement[" + index.serialize() + "].Element[0..]" and
556556
output = "Argument[self].Element[?]"
557557
or
558558
input = "Argument[self].WithoutElement[0..]" and
559559
output = "Argument[self]"
560560
else (
561-
input = "Argument[self].WithoutElement[" + cv.serialize() + "]" and
561+
input = "Argument[self].WithoutElement[" + index.serialize() + "]" and
562562
output = "Argument[self]"
563563
)
564564
)
565565
or
566-
input = "Argument[self].Element[" + cv.serialize() + ",?]" and
566+
input = "Argument[self].Element[" + index.serialize() + ",?]" and
567567
output = "ReturnValue"
568568
) and
569569
preservesValue = true
@@ -795,17 +795,17 @@ module Array {
795795
}
796796

797797
private class FetchKnownSummary extends FetchSummary {
798-
ConstantValue cv;
798+
ConstantValue index;
799799

800800
FetchKnownSummary() {
801-
this = "fetch(" + cv.serialize() + ")" and
802-
cv = mc.getArgument(0).getConstantValue() and
803-
not cv.isInt(any(int i | i < 0))
801+
this = "fetch(" + index.serialize() + ")" and
802+
index = mc.getArgument(0).getConstantValue() and
803+
not index.isInt(any(int i | i < 0))
804804
}
805805

806806
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
807807
(
808-
input = "Argument[self].Element[?," + cv.serialize() + "]" and
808+
input = "Argument[self].Element[?," + index.serialize() + "]" and
809809
output = "ReturnValue"
810810
or
811811
input = "Argument[0]" and
@@ -821,8 +821,8 @@ module Array {
821821
private class FetchUnknownSummary extends FetchSummary {
822822
FetchUnknownSummary() {
823823
this = "fetch(index)" and
824-
not exists(ConstantValue cv |
825-
cv = mc.getArgument(0).getConstantValue() and not cv.isInt(any(int i | i < 0))
824+
not exists(ConstantValue index |
825+
index = mc.getArgument(0).getConstantValue() and not index.isInt(any(int i | i < 0))
826826
)
827827
}
828828

@@ -1867,9 +1867,9 @@ module Enumerable {
18671867
output = "ReturnValue.Element[?]" and
18681868
preservesValue = true
18691869
or
1870-
exists(ConstantValue cv |
1871-
not cv.isInt(_) and
1872-
input = "Argument[self].WithElement[" + cv.serialize() + "]" and
1870+
exists(ConstantValue index |
1871+
not index.isInt(_) and
1872+
input = "Argument[self].WithElement[" + index.serialize() + "]" and
18731873
output = "ReturnValue" and
18741874
preservesValue = true
18751875
)

ruby/ql/lib/codeql/ruby/frameworks/core/Hash.qll

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ private import codeql.ruby.dataflow.internal.DataFlowDispatch
1717
*/
1818
module Hash {
1919
// cannot use API graphs due to negative recursion
20-
private predicate isHashLiteralPair(Pair pair, ConstantValue cv) {
21-
cv = DataFlow::Content::getKnownElementIndex(pair.getKey()) and
20+
private predicate isHashLiteralPair(Pair pair, ConstantValue key) {
21+
key = DataFlow::Content::getKnownElementIndex(pair.getKey()) and
2222
pair = any(MethodCall mc | mc.getMethodName() = "[]").getAnArgument()
2323
}
2424

@@ -44,23 +44,23 @@ module Hash {
4444
}
4545

4646
private class HashLiteralNonSymbolSummary extends SummarizedCallable {
47-
private ConstantValue cv;
47+
private ConstantValue key;
4848

4949
HashLiteralNonSymbolSummary() {
5050
this = "Hash.[]" and
51-
isHashLiteralPair(_, cv) and
52-
not cv.isSymbol(_)
51+
isHashLiteralPair(_, key) and
52+
not key.isSymbol(_)
5353
}
5454

5555
final override MethodCall getACall() {
5656
result = API::getTopLevelMember("Hash").getAMethodCall("[]").getExprNode().getExpr() and
57-
isHashLiteralPair(result.getAnArgument(), cv)
57+
isHashLiteralPair(result.getAnArgument(), key)
5858
}
5959

6060
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
6161
// { 'nonsymbol' => x }
62-
input = "Argument[0..].PairValue[" + cv.serialize() + "]" and
63-
output = "ReturnValue.Element[" + cv.serialize() + "]" and
62+
input = "Argument[0..].PairValue[" + key.serialize() + "]" and
63+
output = "ReturnValue.Element[" + key.serialize() + "]" and
6464
preservesValue = true
6565
}
6666
}
@@ -110,27 +110,27 @@ module Hash {
110110
*/
111111
private class HashNewSuccessivePairsSummary extends SummarizedCallable {
112112
private int i;
113-
private ConstantValue cv;
113+
private ConstantValue key;
114114

115115
HashNewSuccessivePairsSummary() {
116-
this = "Hash[" + i + ", " + cv.serialize() + "]" and
116+
this = "Hash[" + i + ", " + key.serialize() + "]" and
117117
i % 2 = 1 and
118118
exists(ElementReference er |
119-
cv = er.getArgument(i - 1).getConstantValue() and
119+
key = er.getArgument(i - 1).getConstantValue() and
120120
exists(er.getArgument(i))
121121
)
122122
}
123123

124124
final override ElementReference getACall() {
125125
result.getReceiver() = API::getTopLevelMember("Hash").getAUse().asExpr().getExpr() and
126-
cv = result.getArgument(i - 1).getConstantValue() and
126+
key = result.getArgument(i - 1).getConstantValue() and
127127
exists(result.getArgument(i))
128128
}
129129

130130
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
131131
// Hash[:symbol, x]
132132
input = "Argument[" + i + "]" and
133-
output = "ReturnValue.Element[" + cv.serialize() + "]" and
133+
output = "ReturnValue.Element[" + key.serialize() + "]" and
134134
preservesValue = true
135135
}
136136
}
@@ -165,21 +165,21 @@ module Hash {
165165
}
166166

167167
private class StoreKnownSummary extends StoreSummary {
168-
private ConstantValue cv;
168+
private ConstantValue key;
169169

170170
StoreKnownSummary() {
171-
cv = DataFlow::Content::getKnownElementIndex(mc.getArgument(0)) and
172-
this = "store(" + cv.serialize() + ")"
171+
key = DataFlow::Content::getKnownElementIndex(mc.getArgument(0)) and
172+
this = "store(" + key.serialize() + ")"
173173
}
174174

175175
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
176176
super.propagatesFlowExt(input, output, preservesValue)
177177
or
178178
input = "Argument[1]" and
179-
output = "Argument[self].Element[" + cv.serialize() + "]" and
179+
output = "Argument[self].Element[" + key.serialize() + "]" and
180180
preservesValue = true
181181
or
182-
input = "Argument[self].WithoutElement[" + cv.serialize() + "]" and
182+
input = "Argument[self].WithoutElement[" + key.serialize() + "]" and
183183
output = "Argument[self]" and
184184
preservesValue = true
185185
}
@@ -210,17 +210,17 @@ module Hash {
210210
}
211211

212212
private class AssocKnownSummary extends AssocSummary {
213-
private ConstantValue cv;
213+
private ConstantValue key;
214214

215215
AssocKnownSummary() {
216-
this = "assoc(" + cv.serialize() + "]" and
217-
not cv.isInt(_) and // exclude arrays
216+
this = "assoc(" + key.serialize() + "]" and
217+
not key.isInt(_) and // exclude arrays
218218
mc.getNumberOfArguments() = 1 and
219-
cv = DataFlow::Content::getKnownElementIndex(mc.getArgument(0))
219+
key = DataFlow::Content::getKnownElementIndex(mc.getArgument(0))
220220
}
221221

222222
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
223-
input = "Argument[self].Element[" + cv.serialize() + ",?]" and
223+
input = "Argument[self].Element[" + key.serialize() + ",?]" and
224224
output = "ReturnValue.Element[1]" and
225225
preservesValue = true
226226
}
@@ -325,18 +325,18 @@ abstract private class FetchValuesSummary extends SummarizedCallable {
325325
}
326326

327327
private class FetchValuesKnownSummary extends FetchValuesSummary {
328-
ConstantValue cv;
328+
ConstantValue key;
329329

330330
FetchValuesKnownSummary() {
331331
forex(Expr arg | arg = mc.getAnArgument() | exists(arg.getConstantValue())) and
332-
cv = mc.getAnArgument().getConstantValue() and
333-
this = "fetch_values(" + cv.serialize() + ")"
332+
key = mc.getAnArgument().getConstantValue() and
333+
this = "fetch_values(" + key.serialize() + ")"
334334
}
335335

336336
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
337337
super.propagatesFlowExt(input, output, preservesValue)
338338
or
339-
input = "Argument[self].Element[" + cv.serialize() + "]" and
339+
input = "Argument[self].Element[" + key.serialize() + "]" and
340340
output = "ReturnValue.Element[?]" and
341341
preservesValue = true
342342
}
@@ -407,16 +407,16 @@ abstract private class SliceSummary extends SummarizedCallable {
407407
}
408408

409409
private class SliceKnownSummary extends SliceSummary {
410-
ConstantValue cv;
410+
ConstantValue key;
411411

412412
SliceKnownSummary() {
413-
cv = mc.getAnArgument().getConstantValue() and
414-
this = "slice(" + cv.serialize() + ")" and
415-
not cv.isInt(_) // covered in `Array.qll`
413+
key = mc.getAnArgument().getConstantValue() and
414+
this = "slice(" + key.serialize() + ")" and
415+
not key.isInt(_) // covered in `Array.qll`
416416
}
417417

418418
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
419-
input = "Argument[self].WithElement[?," + cv.serialize() + "]" and
419+
input = "Argument[self].WithElement[?," + key.serialize() + "]" and
420420
output = "ReturnValue" and
421421
preservesValue = true
422422
}

0 commit comments

Comments
 (0)