File tree Expand file tree Collapse file tree 3 files changed +23
-9
lines changed
test/library-tests/dataflow/barrier-guards Expand file tree Collapse file tree 3 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -20,19 +20,26 @@ private import codeql.ruby.CFG
20
20
class StringConstCompare extends DataFlow:: BarrierGuard ,
21
21
CfgNodes:: ExprNodes:: ComparisonOperationCfgNode {
22
22
private CfgNode checkedNode ;
23
+ // The value of the condition that results in the node being validated.
24
+ private boolean checkedBranch ;
23
25
24
26
StringConstCompare ( ) {
25
27
exists ( CfgNodes:: ExprNodes:: StringLiteralCfgNode strLitNode |
26
- this .getExpr ( ) instanceof EqExpr or
27
- this .getExpr ( ) instanceof CaseEqExpr
28
+ this .getExpr ( ) instanceof EqExpr and checkedBranch = true
29
+ or
30
+ this .getExpr ( ) instanceof CaseEqExpr and checkedBranch = true
31
+ or
32
+ this .getExpr ( ) instanceof NEExpr and checkedBranch = false
28
33
|
29
34
this .getLeftOperand ( ) = strLitNode and this .getRightOperand ( ) = checkedNode
30
35
or
31
36
this .getLeftOperand ( ) = checkedNode and this .getRightOperand ( ) = strLitNode
32
37
)
33
38
}
34
39
35
- override predicate checks ( CfgNode expr , boolean branch ) { expr = checkedNode and branch = true }
40
+ override predicate checks ( CfgNode expr , boolean branch ) {
41
+ expr = checkedNode and branch = checkedBranch
42
+ }
36
43
}
37
44
38
45
/**
Original file line number Diff line number Diff line change 1
- | barrier-guards.rb:3:4:3:15 | ... == ... | barrier-guards.rb:4:15:4:17 | foo | barrier-guards.rb:3:4:3:6 | foo | true |
2
- | barrier-guards.rb:9:4:9:24 | call to include? | barrier-guards.rb:10:15:10:17 | foo | barrier-guards.rb:9:21:9:23 | foo | true |
1
+ | barrier-guards.rb:3:4:3:15 | ... == ... | barrier-guards.rb:4:13:4:15 | foo | barrier-guards.rb:3:4:3:6 | foo | true |
2
+ | barrier-guards.rb:9:4:9:24 | call to include? | barrier-guards.rb:10:13:10:15 | foo | barrier-guards.rb:9:21:9:23 | foo | true |
3
+ | barrier-guards.rb:15:4:15:15 | ... != ... | barrier-guards.rb:18:14:18:16 | foo | barrier-guards.rb:15:4:15:6 | foo | false |
Original file line number Diff line number Diff line change 1
1
foo = "foo"
2
2
3
3
if foo == "foo"
4
- do_true_1 foo
4
+ do_true foo
5
5
else
6
- do_false_1 foo
6
+ do_false foo
7
7
end
8
8
9
9
if [ "foo" ] . include? ( foo )
10
- do_true_2 foo
10
+ do_true foo
11
11
else
12
- do_false_2 foo
12
+ do_false foo
13
+ end
14
+
15
+ if foo != "foo"
16
+ do_true foo
17
+ else
18
+ do_false foo
13
19
end
14
20
15
21
do_default foo
You can’t perform that action at this time.
0 commit comments