@@ -17,19 +17,37 @@ private import codeql.ruby.dataflow.internal.DataFlowPublic
17
17
import codeql.ruby.controlflow.internal.Guards as Guards
18
18
import codeql.ruby.controlflow.CfgNodes
19
19
20
- predicate isInBooleanContext ( Expr e ) {
21
- e = any ( ConditionalExpr c ) .getCondition ( )
20
+ private predicate isInBooleanContext ( AstNode n ) {
21
+ exists ( ConditionalExpr i |
22
+ n = i .getCondition ( )
23
+ or
24
+ isInBooleanContext ( i ) and
25
+ n = i .getBranch ( _)
26
+ )
27
+ or
28
+ n = any ( ConditionalLoop parent ) .getCondition ( )
29
+ or
30
+ n = any ( InClause parent ) .getCondition ( )
22
31
or
23
- e = any ( ConditionalLoop l ) . getCondition ( )
32
+ n = any ( LogicalAndExpr op ) . getAnOperand ( )
24
33
or
25
- e = any ( LogicalAndExpr n ) .getAnOperand ( )
34
+ n = any ( LogicalOrExpr op ) .getAnOperand ( )
26
35
or
27
- e = any ( LogicalOrExpr n ) . getAnOperand ( )
36
+ n = any ( NotExpr op ) . getOperand ( )
28
37
or
29
- e = any ( NotExpr n ) .getOperand ( )
38
+ n = any ( StmtSequence parent | isInBooleanContext ( parent ) ) .getLastStmt ( )
39
+ or
40
+ exists ( CaseExpr c , WhenClause w |
41
+ not exists ( c .getValue ( ) ) and
42
+ c .getABranch ( ) = w
43
+ |
44
+ w .getPattern ( _) = n
45
+ or
46
+ w = n
47
+ )
30
48
}
31
49
32
- predicate isGuarded ( LocalVariableReadAccess read ) {
50
+ private predicate isGuarded ( LocalVariableReadAccess read ) {
33
51
exists ( AstCfgNode guard , boolean branch |
34
52
Guards:: guardControlsBlock ( guard , read .getAControlFlowNode ( ) .getBasicBlock ( ) , branch )
35
53
|
@@ -46,7 +64,7 @@ predicate isGuarded(LocalVariableReadAccess read) {
46
64
)
47
65
}
48
66
49
- predicate isNilChecked ( LocalVariableReadAccess read ) {
67
+ private predicate isNilChecked ( LocalVariableReadAccess read ) {
50
68
exists ( MethodCall c | c .getReceiver ( ) = read |
51
69
c .getMethodName ( ) = "nil?"
52
70
or
0 commit comments