Skip to content

Commit 45962f1

Browse files
committed
Ruby: make this unique for each method
Even when summaries are shared in a single class.
1 parent 7a9ddc2 commit 45962f1

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ module Array {
199199
private int i;
200200

201201
ElementReferenceReadKnownSummary() {
202-
this = "[" + i + "]" and
202+
this = mc.getMethodName() + "(" + i + ")" and
203203
mc.getNumberOfArguments() = 1 and
204204
i = getKnownArrayElementContent(mc.getArgument(0)).getIndex()
205205
}
@@ -217,7 +217,7 @@ module Array {
217217
*/
218218
private class ElementReferenceReadUnknownSummary extends ElementReferenceReadSummary {
219219
ElementReferenceReadUnknownSummary() {
220-
this = "[](index)" and
220+
this = mc.getMethodName() + "(index)" and
221221
mc.getNumberOfArguments() = 1 and
222222
isUnknownArrayElementContent(mc.getArgument(0))
223223
}
@@ -1067,7 +1067,7 @@ module Array {
10671067
// `unshift` is an alias for `prepend`
10681068
PrependSummary() {
10691069
mc.getMethodName() = ["prepend", "unshift"] and
1070-
this = "prepend(" + mc.getNumberOfArguments() + ")"
1070+
this = mc.getMethodName() + "(" + mc.getNumberOfArguments() + ")"
10711071
}
10721072

10731073
override MethodCall getACall() { result = mc }
@@ -2044,7 +2044,7 @@ module Enumerable {
20442044
}
20452045

20462046
private class GrepBlockSummary extends GrepSummary {
2047-
GrepBlockSummary() { this = "grep(block)" and exists(mc.getBlock()) }
2047+
GrepBlockSummary() { this = mc.getMethodName() + "(block)" and exists(mc.getBlock()) }
20482048

20492049
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
20502050
(
@@ -2059,7 +2059,7 @@ module Enumerable {
20592059
}
20602060

20612061
private class GrepNoBlockSummary extends GrepSummary {
2062-
GrepNoBlockSummary() { this = "grep(no_block)" and not exists(mc.getBlock()) }
2062+
GrepNoBlockSummary() { this = mc.getMethodName() + "(no_block)" and not exists(mc.getBlock()) }
20632063

20642064
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
20652065
input = "ArrayElement of Receiver" and
@@ -2090,7 +2090,7 @@ module Enumerable {
20902090
}
20912091

20922092
private class InjectNoArgSummary extends InjectSummary {
2093-
InjectNoArgSummary() { this = "inject(no_arg)" and mc.getNumberOfArguments() = 0 }
2093+
InjectNoArgSummary() { this = mc.getMethodName() + "_no_arg" and mc.getNumberOfArguments() = 0 }
20942094

20952095
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
20962096
// The no-argument variant of inject passes element 0 to the first block
@@ -2110,7 +2110,7 @@ module Enumerable {
21102110
}
21112111

21122112
private class InjectArgSummary extends InjectSummary {
2113-
InjectArgSummary() { this = "inject(arg)" and mc.getNumberOfArguments() > 0 }
2113+
InjectArgSummary() { this = mc.getMethodName() + "_arg" and mc.getNumberOfArguments() > 0 }
21142114

21152115
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
21162116
(
@@ -2139,7 +2139,7 @@ module Enumerable {
21392139

21402140
private class MinOrMaxByNoArgSummary extends MinOrMaxBySummary {
21412141
MinOrMaxByNoArgSummary() {
2142-
this = "min_or_max_by_no_arg" and
2142+
this = mc.getMethodName() + "_no_arg" and
21432143
mc.getNumberOfArguments() = 0
21442144
}
21452145

@@ -2152,7 +2152,7 @@ module Enumerable {
21522152

21532153
private class MinOrMaxByArgSummary extends MinOrMaxBySummary {
21542154
MinOrMaxByArgSummary() {
2155-
this = "min_or_max_by_arg" and
2155+
this = mc.getMethodName() + "_arg" and
21562156
mc.getNumberOfArguments() > 0
21572157
}
21582158

@@ -2174,7 +2174,7 @@ module Enumerable {
21742174

21752175
private class MinOrMaxNoArgNoBlockSummary extends MinOrMaxSummary {
21762176
MinOrMaxNoArgNoBlockSummary() {
2177-
this = "min_or_max_no_arg_no_block" and
2177+
this = mc.getMethodName() + "_no_arg_no_block" and
21782178
mc.getNumberOfArguments() = 0 and
21792179
not exists(mc.getBlock())
21802180
}
@@ -2188,7 +2188,7 @@ module Enumerable {
21882188

21892189
private class MinOrMaxArgNoBlockSummary extends MinOrMaxSummary {
21902190
MinOrMaxArgNoBlockSummary() {
2191-
this = "min_or_max_arg_no_block" and
2191+
this = mc.getMethodName() + "_arg_no_block" and
21922192
mc.getNumberOfArguments() > 0 and
21932193
not exists(mc.getBlock())
21942194
}
@@ -2202,7 +2202,7 @@ module Enumerable {
22022202

22032203
private class MinOrMaxNoArgBlockSummary extends MinOrMaxSummary {
22042204
MinOrMaxNoArgBlockSummary() {
2205-
this = "min_or_max_no_arg_block" and
2205+
this = mc.getMethodName() + "_no_arg_block" and
22062206
mc.getNumberOfArguments() = 0 and
22072207
exists(mc.getBlock())
22082208
}
@@ -2216,7 +2216,7 @@ module Enumerable {
22162216

22172217
private class MinOrMaxArgBlockSummary extends MinOrMaxSummary {
22182218
MinOrMaxArgBlockSummary() {
2219-
this = "min_or_max_arg_block" and
2219+
this = mc.getMethodName() + "_arg_block" and
22202220
mc.getNumberOfArguments() > 0 and
22212221
exists(mc.getBlock())
22222222
}

ruby/ql/test/library-tests/dataflow/array-flow/array-flow.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
failures
2-
| array_flow.rb:4:10:4:13 | ...[...] | Unexpected result: hasTaintFlow=0.1 |
32
edges
43
| array_flow.rb:2:9:2:20 | * ... : | array_flow.rb:3:10:3:10 | a : |
54
| array_flow.rb:2:9:2:20 | * ... : | array_flow.rb:4:10:4:10 | a : |

ruby/ql/test/library-tests/dataflow/array-flow/array_flow.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
def m0(i)
22
a = *source(0.1)
33
sink(a[0]) # $ hasValueFlow=0.1
4-
sink(a[1])
4+
sink(a[1]) # $ hasTaintFlow=0.1
55
sink(a[i]) # $ hasValueFlow=0.1
66
end
77

0 commit comments

Comments
 (0)