@@ -109,15 +109,26 @@ predicate whitelist(Expr e) {
109109
110110/**
111111 * Holds if `e` is part of a conditional node `cond` that evaluates
112- * `e` and checks its value for truthiness.
112+ * `e` and checks its value for truthiness, and the return value of `e`
113+ * is not used for anything other than this truthiness check.
113114 */
114- predicate isConditional ( ASTNode cond , Expr e ) {
115+ predicate isExplicitConditional ( ASTNode cond , Expr e ) {
115116 e = cond .( IfStmt ) .getCondition ( ) or
116117 e = cond .( LoopStmt ) .getTest ( ) or
117118 e = cond .( ConditionalExpr ) .getCondition ( ) or
118- e = cond .( LogicalBinaryExpr ) .getLeftOperand ( ) or
119- // Include `z` in `if (x && z)`.
120- isConditional ( _, cond ) and e = cond .( Expr ) .getUnderlyingValue ( ) .( LogicalBinaryExpr ) .getRightOperand ( )
119+ isExplicitConditional ( _, cond ) and e = cond .( Expr ) .getUnderlyingValue ( ) .( LogicalBinaryExpr ) .getAnOperand ( )
120+ }
121+
122+ /**
123+ * Holds if `e` is part of a conditional node `cond` that evaluates
124+ * `e` and checks its value for truthiness.
125+ *
126+ * The return value of `e` may have other uses besides the truthiness check,
127+ * but if the truthiness check always goes one way, it still indicates an error.
128+ */
129+ predicate isConditional ( ASTNode cond , Expr e ) {
130+ isExplicitConditional ( cond , e ) or
131+ e = cond .( LogicalBinaryExpr ) .getLeftOperand ( )
121132}
122133
123134from ASTNode cond , DataFlow:: AnalyzedNode op , boolean cv , ASTNode sel , string msg
0 commit comments