mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
JS: Fix flow through &&
This is a long-standing bug we've been unable to fix due to noise from type inference.
This commit is contained in:
@@ -1693,7 +1693,11 @@ module DataFlow {
|
||||
exists(Expr predExpr, Expr succExpr |
|
||||
pred = valueNode(predExpr) and succ = valueNode(succExpr)
|
||||
|
|
||||
predExpr = succExpr.(LogicalBinaryExpr).getAnOperand()
|
||||
predExpr = succExpr.(LogicalOrExpr).getAnOperand()
|
||||
or
|
||||
predExpr = succExpr.(NullishCoalescingExpr).getAnOperand()
|
||||
or
|
||||
predExpr = succExpr.(LogicalAndExpr).getRightOperand()
|
||||
or
|
||||
predExpr = succExpr.(ConditionalExpr).getABranch()
|
||||
or
|
||||
|
||||
@@ -238,6 +238,26 @@ private class AnalyzedBinaryExpr extends DataFlow::AnalyzedValueNode {
|
||||
}
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private predicate falsyValue(AbstractValue value) { value.getBooleanValue() = false }
|
||||
|
||||
/**
|
||||
* Flow analysis for `&&` operators.
|
||||
*/
|
||||
private class AnalyzedLogicalAndExpr extends DataFlow::AnalyzedValueNode {
|
||||
override LogicalAndExpr astNode;
|
||||
|
||||
pragma[nomagic]
|
||||
private AnalyzedValueNode leftOperand() { result = astNode.getLeftOperand().analyze() }
|
||||
|
||||
override AbstractValue getALocalValue() {
|
||||
result = super.getALocalValue()
|
||||
or
|
||||
result = this.leftOperand().getALocalValue() and
|
||||
falsyValue(result)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `n`th operand of the given `+` or `+=` expression.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user