Skip to content

Commit d362296

Browse files
authored
Merge pull request github#10864 from hvitved/ruby/get-a-barrier-node-join-fix
Ruby: Fix bad join-order in `BarrierGuard::getABarrierNode`
2 parents 543e2f5 + 6c765a9 commit d362296

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,15 +440,24 @@ signature predicate guardChecksSig(CfgNodes::ExprCfgNode g, CfgNode e, boolean b
440440
* in data flow and taint tracking.
441441
*/
442442
module BarrierGuard<guardChecksSig/3 guardChecks> {
443+
pragma[nomagic]
444+
private predicate guardChecksSsaDef(CfgNodes::ExprCfgNode g, boolean branch, Ssa::Definition def) {
445+
guardChecks(g, def.getARead(), branch)
446+
}
447+
448+
pragma[nomagic]
449+
private predicate guardControlsSsaDef(
450+
CfgNodes::ExprCfgNode g, boolean branch, Ssa::Definition def, Node n
451+
) {
452+
def.getARead() = n.asExpr() and
453+
guardControlsBlock(g, n.asExpr().getBasicBlock(), branch)
454+
}
455+
443456
/** Gets a node that is safely guarded by the given guard check. */
444457
Node getABarrierNode() {
445-
exists(
446-
CfgNodes::ExprCfgNode g, boolean branch, CfgNodes::ExprCfgNode testedNode, Ssa::Definition def
447-
|
448-
def.getARead() = testedNode and
449-
def.getARead() = result.asExpr() and
450-
guardChecks(g, testedNode, branch) and
451-
guardControlsBlock(g, result.asExpr().getBasicBlock(), branch)
458+
exists(CfgNodes::ExprCfgNode g, boolean branch, Ssa::Definition def |
459+
guardChecksSsaDef(g, branch, def) and
460+
guardControlsSsaDef(g, branch, def, result)
452461
)
453462
or
454463
result.asExpr() = getAMaybeGuardedCapturedDef().getARead()

0 commit comments

Comments
 (0)