Skip to content

Commit 4a1163b

Browse files
authored
Merge pull request #14109 from hvitved/ruby/hide-desugared-assignments-in-dataflow
2 parents ecee427 + 89e9d25 commit 4a1163b

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,7 @@ import Cached
558558

559559
/** Holds if `n` should be hidden from path explanations. */
560560
predicate nodeIsHidden(Node n) {
561-
exists(SsaImpl::DefinitionExt def | def = n.(SsaDefinitionExtNode).getDefinitionExt() |
562-
not def instanceof Ssa::WriteDefinition
563-
)
561+
n.(SsaDefinitionExtNode).isHidden()
564562
or
565563
n = LocalFlow::getParameterDefNode(_)
566564
or
@@ -593,6 +591,13 @@ class SsaDefinitionExtNode extends NodeImpl, TSsaDefinitionExtNode {
593591
/** Gets the underlying variable. */
594592
Variable getVariable() { result = def.getSourceVariable() }
595593

594+
/** Holds if this node should be hidden from path explanations. */
595+
predicate isHidden() {
596+
not def instanceof Ssa::WriteDefinition
597+
or
598+
isDesugarNode(def.(Ssa::WriteDefinition).getWriteAccess().getExpr())
599+
}
600+
596601
override CfgScope getCfgScope() { result = def.getBasicBlock().getScope() }
597602

598603
override Location getLocationImpl() { result = def.getLocation() }
@@ -1593,7 +1598,11 @@ class CastNode extends Node {
15931598
*/
15941599
predicate neverSkipInPathGraph(Node n) {
15951600
// ensure that all variable assignments are included in the path graph
1596-
n.(SsaDefinitionExtNode).getDefinitionExt() instanceof Ssa::WriteDefinition
1601+
n =
1602+
any(SsaDefinitionExtNode def |
1603+
def.getDefinitionExt() instanceof Ssa::WriteDefinition and
1604+
not def.isHidden()
1605+
)
15971606
}
15981607

15991608
class DataFlowExpr = CfgNodes::ExprCfgNode;

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,8 @@ edges
203203
| array_flow.rb:80:13:80:21 | call to source | array_flow.rb:80:5:80:5 | a [element 1] |
204204
| array_flow.rb:81:8:81:8 | c | array_flow.rb:83:10:83:10 | c |
205205
| array_flow.rb:81:8:81:8 | c | array_flow.rb:83:10:83:10 | c |
206-
| array_flow.rb:81:15:81:15 | __synth__3 [element 1] | array_flow.rb:81:8:81:8 | c |
207-
| array_flow.rb:81:15:81:15 | __synth__3 [element 1] | array_flow.rb:81:8:81:8 | c |
208-
| array_flow.rb:81:15:81:15 | a [element 1] | array_flow.rb:81:15:81:15 | __synth__3 [element 1] |
209-
| array_flow.rb:81:15:81:15 | a [element 1] | array_flow.rb:81:15:81:15 | __synth__3 [element 1] |
206+
| array_flow.rb:81:15:81:15 | a [element 1] | array_flow.rb:81:8:81:8 | c |
207+
| array_flow.rb:81:15:81:15 | a [element 1] | array_flow.rb:81:8:81:8 | c |
210208
| array_flow.rb:88:5:88:5 | a [element 1] | array_flow.rb:89:9:89:9 | a [element 1] |
211209
| array_flow.rb:88:5:88:5 | a [element 1] | array_flow.rb:89:9:89:9 | a [element 1] |
212210
| array_flow.rb:88:13:88:22 | call to source | array_flow.rb:88:5:88:5 | a [element 1] |
@@ -4468,8 +4466,6 @@ nodes
44684466
| array_flow.rb:80:13:80:21 | call to source | semmle.label | call to source |
44694467
| array_flow.rb:81:8:81:8 | c | semmle.label | c |
44704468
| array_flow.rb:81:8:81:8 | c | semmle.label | c |
4471-
| array_flow.rb:81:15:81:15 | __synth__3 [element 1] | semmle.label | __synth__3 [element 1] |
4472-
| array_flow.rb:81:15:81:15 | __synth__3 [element 1] | semmle.label | __synth__3 [element 1] |
44734469
| array_flow.rb:81:15:81:15 | a [element 1] | semmle.label | a [element 1] |
44744470
| array_flow.rb:81:15:81:15 | a [element 1] | semmle.label | a [element 1] |
44754471
| array_flow.rb:83:10:83:10 | c | semmle.label | c |

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ edges
8181
| hash_flow.rb:96:30:96:33 | hash [element :a] | hash_flow.rb:96:13:96:34 | call to try_convert [element :a] |
8282
| hash_flow.rb:97:10:97:14 | hash2 [element :a] | hash_flow.rb:97:10:97:18 | ...[...] |
8383
| hash_flow.rb:105:5:105:5 | b | hash_flow.rb:106:10:106:10 | b |
84-
| hash_flow.rb:105:21:105:30 | __synth__0 | hash_flow.rb:105:5:105:5 | b |
85-
| hash_flow.rb:105:21:105:30 | call to taint | hash_flow.rb:105:21:105:30 | __synth__0 |
84+
| hash_flow.rb:105:21:105:30 | call to taint | hash_flow.rb:105:5:105:5 | b |
8685
| hash_flow.rb:113:5:113:5 | b | hash_flow.rb:115:10:115:10 | b |
8786
| hash_flow.rb:113:9:113:12 | [post] hash [element :a] | hash_flow.rb:114:10:114:13 | hash [element :a] |
8887
| hash_flow.rb:113:9:113:34 | call to store | hash_flow.rb:113:5:113:5 | b |
@@ -1063,7 +1062,6 @@ nodes
10631062
| hash_flow.rb:97:10:97:14 | hash2 [element :a] | semmle.label | hash2 [element :a] |
10641063
| hash_flow.rb:97:10:97:18 | ...[...] | semmle.label | ...[...] |
10651064
| hash_flow.rb:105:5:105:5 | b | semmle.label | b |
1066-
| hash_flow.rb:105:21:105:30 | __synth__0 | semmle.label | __synth__0 |
10671065
| hash_flow.rb:105:21:105:30 | call to taint | semmle.label | call to taint |
10681066
| hash_flow.rb:106:10:106:10 | b | semmle.label | b |
10691067
| hash_flow.rb:113:5:113:5 | b | semmle.label | b |

0 commit comments

Comments
 (0)