Skip to content

Commit b816c79

Browse files
committed
Ruby: Include all assignments in data flow paths
1 parent 79cd761 commit b816c79

File tree

51 files changed

+5859
-2770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+5859
-2770
lines changed

ruby/ql/lib/codeql/ruby/dataflow/SSA.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ module Ssa {
216216
)
217217
}
218218

219-
final override string toString() { result = Definition.super.toString() }
219+
final override string toString() { result = write.toString() }
220220

221-
final override Location getLocation() { result = this.getControlFlowNode().getLocation() }
221+
final override Location getLocation() { result = write.getLocation() }
222222
}
223223

224224
/**

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,7 @@ import Cached
528528
/** Holds if `n` should be hidden from path explanations. */
529529
predicate nodeIsHidden(Node n) {
530530
exists(SsaImpl::DefinitionExt def | def = n.(SsaDefinitionExtNode).getDefinitionExt() |
531-
def instanceof Ssa::PhiNode or
532-
def instanceof SsaImpl::PhiReadNode or
533-
def instanceof Ssa::CapturedEntryDefinition or
534-
def instanceof Ssa::CapturedCallDefinition
531+
not def instanceof Ssa::WriteDefinition
535532
)
536533
or
537534
n = LocalFlow::getParameterDefNode(_)
@@ -1333,7 +1330,15 @@ private module PostUpdateNodes {
13331330
private import PostUpdateNodes
13341331

13351332
/** A node that performs a type cast. */
1336-
class CastNode extends Node instanceof ReturningNode { }
1333+
class CastNode extends Node {
1334+
CastNode() {
1335+
// ensure that actual return nodes are included in the path graph
1336+
this instanceof ReturningNode
1337+
or
1338+
// ensure that all variable assignments are included in the path graph
1339+
this.(SsaDefinitionExtNode).getDefinitionExt() instanceof Ssa::WriteDefinition
1340+
}
1341+
}
13371342

13381343
class DataFlowExpr = CfgNodes::ExprCfgNode;
13391344

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

Lines changed: 2799 additions & 1181 deletions
Large diffs are not rendered by default.

ruby/ql/test/library-tests/dataflow/flow-summaries/semantics.expected

Lines changed: 366 additions & 160 deletions
Large diffs are not rendered by default.

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,10 @@ edges
207207
| instance_variables.rb:114:6:114:10 | foo13 [@field] : | instance_variables.rb:13:5:15:7 | self in get_field [@field] : |
208208
| instance_variables.rb:114:6:114:10 | foo13 [@field] : | instance_variables.rb:114:6:114:20 | call to get_field |
209209
| instance_variables.rb:114:6:114:10 | foo13 [@field] : | instance_variables.rb:114:6:114:20 | call to get_field |
210-
| instance_variables.rb:116:9:116:26 | call to new [@field] : | instance_variables.rb:117:6:117:10 | foo15 [@field] : |
211-
| instance_variables.rb:116:9:116:26 | call to new [@field] : | instance_variables.rb:117:6:117:10 | foo15 [@field] : |
210+
| instance_variables.rb:116:1:116:5 | foo15 [@field] : | instance_variables.rb:117:6:117:10 | foo15 [@field] : |
211+
| instance_variables.rb:116:1:116:5 | foo15 [@field] : | instance_variables.rb:117:6:117:10 | foo15 [@field] : |
212+
| instance_variables.rb:116:9:116:26 | call to new [@field] : | instance_variables.rb:116:1:116:5 | foo15 [@field] : |
213+
| instance_variables.rb:116:9:116:26 | call to new [@field] : | instance_variables.rb:116:1:116:5 | foo15 [@field] : |
212214
| instance_variables.rb:116:17:116:25 | call to taint : | instance_variables.rb:22:20:22:24 | field : |
213215
| instance_variables.rb:116:17:116:25 | call to taint : | instance_variables.rb:22:20:22:24 | field : |
214216
| instance_variables.rb:116:17:116:25 | call to taint : | instance_variables.rb:116:9:116:26 | call to new [@field] : |
@@ -227,8 +229,10 @@ edges
227229
| instance_variables.rb:120:6:120:10 | foo16 [@field] : | instance_variables.rb:13:5:15:7 | self in get_field [@field] : |
228230
| instance_variables.rb:120:6:120:10 | foo16 [@field] : | instance_variables.rb:120:6:120:20 | call to get_field |
229231
| instance_variables.rb:120:6:120:10 | foo16 [@field] : | instance_variables.rb:120:6:120:20 | call to get_field |
230-
| instance_variables.rb:121:7:121:24 | call to new : | instance_variables.rb:122:6:122:8 | bar |
231-
| instance_variables.rb:121:7:121:24 | call to new : | instance_variables.rb:122:6:122:8 | bar |
232+
| instance_variables.rb:121:1:121:3 | bar : | instance_variables.rb:122:6:122:8 | bar |
233+
| instance_variables.rb:121:1:121:3 | bar : | instance_variables.rb:122:6:122:8 | bar |
234+
| instance_variables.rb:121:7:121:24 | call to new : | instance_variables.rb:121:1:121:3 | bar : |
235+
| instance_variables.rb:121:7:121:24 | call to new : | instance_variables.rb:121:1:121:3 | bar : |
232236
nodes
233237
| captured_variables.rb:1:24:1:24 | x : | semmle.label | x : |
234238
| captured_variables.rb:1:24:1:24 | x : | semmle.label | x : |
@@ -424,6 +428,8 @@ nodes
424428
| instance_variables.rb:114:6:114:10 | foo13 [@field] : | semmle.label | foo13 [@field] : |
425429
| instance_variables.rb:114:6:114:20 | call to get_field | semmle.label | call to get_field |
426430
| instance_variables.rb:114:6:114:20 | call to get_field | semmle.label | call to get_field |
431+
| instance_variables.rb:116:1:116:5 | foo15 [@field] : | semmle.label | foo15 [@field] : |
432+
| instance_variables.rb:116:1:116:5 | foo15 [@field] : | semmle.label | foo15 [@field] : |
427433
| instance_variables.rb:116:9:116:26 | call to new [@field] : | semmle.label | call to new [@field] : |
428434
| instance_variables.rb:116:9:116:26 | call to new [@field] : | semmle.label | call to new [@field] : |
429435
| instance_variables.rb:116:17:116:25 | call to taint : | semmle.label | call to taint : |
@@ -442,6 +448,8 @@ nodes
442448
| instance_variables.rb:120:6:120:10 | foo16 [@field] : | semmle.label | foo16 [@field] : |
443449
| instance_variables.rb:120:6:120:20 | call to get_field | semmle.label | call to get_field |
444450
| instance_variables.rb:120:6:120:20 | call to get_field | semmle.label | call to get_field |
451+
| instance_variables.rb:121:1:121:3 | bar : | semmle.label | bar : |
452+
| instance_variables.rb:121:1:121:3 | bar : | semmle.label | bar : |
445453
| instance_variables.rb:121:7:121:24 | call to new : | semmle.label | call to new : |
446454
| instance_variables.rb:121:7:121:24 | call to new : | semmle.label | call to new : |
447455
| instance_variables.rb:122:6:122:8 | bar | semmle.label | bar |

0 commit comments

Comments
 (0)