Skip to content

Commit 9cd2247

Browse files
committed
Java: expose support for more general BarrierGuards.
1 parent 09058e4 commit 9cd2247

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowUtil.qll

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,24 +375,48 @@ class ContentSet instanceof Content {
375375
}
376376

377377
/**
378-
* Holds if the guard `g` validates the expression `e` upon evaluating to `branch`.
378+
* Holds if the guard `g` validates the expression `e` upon evaluating to `gv`.
379379
*
380380
* The expression `e` is expected to be a syntactic part of the guard `g`.
381381
* For example, the guard `g` might be a call `isSafe(x)` and the expression `e`
382382
* the argument `x`.
383383
*/
384-
signature predicate guardChecksSig(Guard g, Expr e, boolean branch);
384+
signature predicate valueGuardChecksSig(Guard g, Expr e, GuardValue gv);
385385

386386
/**
387387
* Provides a set of barrier nodes for a guard that validates an expression.
388388
*
389389
* This is expected to be used in `isBarrier`/`isSanitizer` definitions
390390
* in data flow and taint tracking.
391391
*/
392-
module BarrierGuard<guardChecksSig/3 guardChecks> {
392+
module BarrierGuardValue<valueGuardChecksSig/3 guardChecks> {
393393
/** Gets a node that is safely guarded by the given guard check. */
394394
Node getABarrierNode() {
395395
SsaFlow::asNode(result) =
396396
SsaImpl::DataFlowIntegration::BarrierGuard<guardChecks/3>::getABarrierNode()
397397
}
398398
}
399+
400+
/**
401+
* Holds if the guard `g` validates the expression `e` upon evaluating to `branch`.
402+
*
403+
* The expression `e` is expected to be a syntactic part of the guard `g`.
404+
* For example, the guard `g` might be a call `isSafe(x)` and the expression `e`
405+
* the argument `x`.
406+
*/
407+
signature predicate guardChecksSig(Guard g, Expr e, boolean branch);
408+
409+
/**
410+
* Provides a set of barrier nodes for a guard that validates an expression.
411+
*
412+
* This is expected to be used in `isBarrier`/`isSanitizer` definitions
413+
* in data flow and taint tracking.
414+
*/
415+
module BarrierGuard<guardChecksSig/3 guardChecks> {
416+
private predicate guardChecks0(Guard g, Expr e, GuardValue gv) {
417+
guardChecks(g, e, gv.asBooleanValue())
418+
}
419+
420+
/** Gets a node that is safely guarded by the given guard check. */
421+
Node getABarrierNode() { result = BarrierGuardValue<guardChecks0/3>::getABarrierNode() }
422+
}

java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,14 @@ private module Cached {
564564
DataFlowIntegrationImpl::localMustFlowStep(v, nodeFrom, nodeTo)
565565
}
566566

567-
signature predicate guardChecksSig(Guards::Guard g, Expr e, boolean branch);
567+
signature predicate guardChecksSig(Guards::Guard g, Expr e, Guards::GuardValue gv);
568568

569569
cached // nothing is actually cached
570570
module BarrierGuard<guardChecksSig/3 guardChecks> {
571571
private predicate guardChecksAdjTypes(
572572
Guards::Guards_v3::Guard g, Expr e, Guards::GuardValue gv
573573
) {
574-
guardChecks(g, e, gv.asBooleanValue())
574+
guardChecks(g, e, gv)
575575
}
576576

577577
private predicate guardChecksWithWrappers(

0 commit comments

Comments
 (0)