Skip to content

Commit 83d3e65

Browse files
committed
Ruby: Implement localMustFlowStep
1 parent 07910b0 commit 83d3e65

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,7 +1972,26 @@ private predicate mustHaveCollectionType(Node n, DataFlowType t) {
19721972
not n instanceof SynthSplatParameterNode
19731973
}
19741974

1975-
predicate localMustFlowStep(Node node1, Node node2) { none() }
1975+
predicate localMustFlowStep(Node node1, Node node2) {
1976+
node1 = SsaFlow::toParameterNodeImpl(node2)
1977+
or
1978+
exists(SsaImpl::Definition def |
1979+
def.(Ssa::WriteDefinition).assigns(node1.asExpr()) and
1980+
node2.(SsaDefinitionExtNode).getDefinitionExt() = def
1981+
or
1982+
def = node1.(SsaDefinitionExtNode).getDefinitionExt() and
1983+
node2.asExpr() = SsaImpl::getARead(def)
1984+
)
1985+
or
1986+
node1.asExpr() = node2.asExpr().(CfgNodes::ExprNodes::AssignExprCfgNode).getRhs()
1987+
or
1988+
node1.asExpr() = node2.asExpr().(CfgNodes::ExprNodes::BlockArgumentCfgNode).getValue()
1989+
or
1990+
node2.(ImplicitBlockArgumentNode).getParameterNode(_) = node1
1991+
or
1992+
FlowSummaryImpl::Private::Steps::summaryLocalMustFlowStep(node1.(FlowSummaryNode).getSummaryNode(),
1993+
node2.(FlowSummaryNode).getSummaryNode())
1994+
}
19761995

19771996
/** Gets the type of `n` used for type pruning. */
19781997
DataFlowType getNodeType(Node n) {

ruby/ql/test/library-tests/dataflow/global/Flow.expected

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@ edges
77
| blocks.rb:24:18:24:18 | x | blocks.rb:25:8:25:8 | x | provenance | |
88
| callbacks.rb:9:15:9:15 | x | callbacks.rb:10:12:10:12 | x | provenance | |
99
| callbacks.rb:10:12:10:12 | x | callbacks.rb:17:15:17:15 | x | provenance | |
10-
| callbacks.rb:10:12:10:12 | x | callbacks.rb:18:15:18:15 | x | provenance | |
1110
| callbacks.rb:13:20:13:20 | x | callbacks.rb:14:14:14:14 | x | provenance | |
1211
| callbacks.rb:14:14:14:14 | x | callbacks.rb:9:15:9:15 | x | provenance | |
1312
| callbacks.rb:17:15:17:15 | x | callbacks.rb:17:25:17:25 | x | provenance | |
1413
| callbacks.rb:17:31:17:38 | call to taint | callbacks.rb:13:20:13:20 | x | provenance | |
15-
| callbacks.rb:18:15:18:15 | x | callbacks.rb:18:25:18:25 | x | provenance | |
1614
| callbacks.rb:20:17:20:17 | x | callbacks.rb:21:11:21:11 | x | provenance | |
1715
| callbacks.rb:21:11:21:11 | x | callbacks.rb:28:31:28:31 | x | provenance | |
18-
| callbacks.rb:21:11:21:11 | x | callbacks.rb:29:29:29:29 | x | provenance | |
1916
| callbacks.rb:24:23:24:23 | x | callbacks.rb:25:17:25:17 | x | provenance | |
2017
| callbacks.rb:25:17:25:17 | x | callbacks.rb:20:17:20:17 | x | provenance | |
2118
| callbacks.rb:28:18:28:25 | call to taint | callbacks.rb:24:23:24:23 | x | provenance | |
2219
| callbacks.rb:28:31:28:31 | x | callbacks.rb:28:39:28:39 | x | provenance | |
23-
| callbacks.rb:29:29:29:29 | x | callbacks.rb:29:37:29:37 | x | provenance | |
2420
| captured_variables.rb:9:24:9:24 | x | captured_variables.rb:11:5:11:6 | fn : [lambda] [captured x] | provenance | |
2521
| captured_variables.rb:11:5:11:6 | fn : [lambda] [captured x] | captured_variables.rb:10:20:10:20 | x | provenance | |
2622
| captured_variables.rb:13:20:13:29 | call to taint | captured_variables.rb:9:24:9:24 | x | provenance | |
@@ -295,17 +291,13 @@ nodes
295291
| callbacks.rb:17:15:17:15 | x | semmle.label | x |
296292
| callbacks.rb:17:25:17:25 | x | semmle.label | x |
297293
| callbacks.rb:17:31:17:38 | call to taint | semmle.label | call to taint |
298-
| callbacks.rb:18:15:18:15 | x | semmle.label | x |
299-
| callbacks.rb:18:25:18:25 | x | semmle.label | x |
300294
| callbacks.rb:20:17:20:17 | x | semmle.label | x |
301295
| callbacks.rb:21:11:21:11 | x | semmle.label | x |
302296
| callbacks.rb:24:23:24:23 | x | semmle.label | x |
303297
| callbacks.rb:25:17:25:17 | x | semmle.label | x |
304298
| callbacks.rb:28:18:28:25 | call to taint | semmle.label | call to taint |
305299
| callbacks.rb:28:31:28:31 | x | semmle.label | x |
306300
| callbacks.rb:28:39:28:39 | x | semmle.label | x |
307-
| callbacks.rb:29:29:29:29 | x | semmle.label | x |
308-
| callbacks.rb:29:37:29:37 | x | semmle.label | x |
309301
| captured_variables.rb:9:24:9:24 | x | semmle.label | x |
310302
| captured_variables.rb:10:20:10:20 | x | semmle.label | x |
311303
| captured_variables.rb:11:5:11:6 | fn : [lambda] [captured x] | semmle.label | fn : [lambda] [captured x] |
@@ -616,15 +608,11 @@ subpaths
616608
| instance_variables.rb:120:6:120:10 | foo16 : Foo [@field] | captured_variables.rb:60:5:62:7 | self in get_field : Foo [@field] | captured_variables.rb:61:9:61:21 | return | instance_variables.rb:120:6:120:20 | call to get_field |
617609
| instance_variables.rb:120:6:120:10 | foo16 : Foo [@field] | instance_variables.rb:13:5:15:7 | self in get_field : Foo [@field] | instance_variables.rb:14:9:14:21 | return | instance_variables.rb:120:6:120:20 | call to get_field |
618610
testFailures
619-
| callbacks.rb:18:25:18:25 | x | Unexpected result: hasValueFlow=1 |
620-
| callbacks.rb:29:37:29:37 | x | Unexpected result: hasValueFlow=2 |
621611
#select
622612
| blocks.rb:8:10:8:14 | yield ... | blocks.rb:14:12:14:20 | call to source | blocks.rb:8:10:8:14 | yield ... | $@ | blocks.rb:14:12:14:20 | call to source | call to source |
623613
| blocks.rb:25:8:25:8 | x | blocks.rb:24:3:24:11 | call to source | blocks.rb:25:8:25:8 | x | $@ | blocks.rb:24:3:24:11 | call to source | call to source |
624614
| callbacks.rb:17:25:17:25 | x | callbacks.rb:17:31:17:38 | call to taint | callbacks.rb:17:25:17:25 | x | $@ | callbacks.rb:17:31:17:38 | call to taint | call to taint |
625-
| callbacks.rb:18:25:18:25 | x | callbacks.rb:17:31:17:38 | call to taint | callbacks.rb:18:25:18:25 | x | $@ | callbacks.rb:17:31:17:38 | call to taint | call to taint |
626615
| callbacks.rb:28:39:28:39 | x | callbacks.rb:28:18:28:25 | call to taint | callbacks.rb:28:39:28:39 | x | $@ | callbacks.rb:28:18:28:25 | call to taint | call to taint |
627-
| callbacks.rb:29:37:29:37 | x | callbacks.rb:28:18:28:25 | call to taint | callbacks.rb:29:37:29:37 | x | $@ | callbacks.rb:28:18:28:25 | call to taint | call to taint |
628616
| captured_variables.rb:10:20:10:20 | x | captured_variables.rb:13:20:13:29 | call to taint | captured_variables.rb:10:20:10:20 | x | $@ | captured_variables.rb:13:20:13:29 | call to taint | call to taint |
629617
| captured_variables.rb:17:14:17:14 | x | captured_variables.rb:20:25:20:34 | call to taint | captured_variables.rb:17:14:17:14 | x | $@ | captured_variables.rb:20:25:20:34 | call to taint | call to taint |
630618
| captured_variables.rb:24:14:24:14 | x | captured_variables.rb:27:48:27:57 | call to taint | captured_variables.rb:24:14:24:14 | x | $@ | captured_variables.rb:27:48:27:57 | call to taint | call to taint |

0 commit comments

Comments
 (0)