Skip to content

Commit ebb9899

Browse files
committed
Guards: Generalise ValidationWrapper to support GuardValue-based BarrierGuards.
1 parent 4a1abc7 commit ebb9899

File tree

3 files changed

+11
-9
lines changed
  • cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal
  • java/ql/lib/semmle/code/java/dataflow/internal
  • shared/controlflow/codeql/controlflow

3 files changed

+11
-9
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,12 +1051,12 @@ module BarrierGuardWithIntParam<guardChecksNodeSig/4 guardChecksNode> {
10511051
}
10521052

10531053
private predicate guardChecksInstr(
1054-
IRGuards::Guards_v1::Guard g, IRGuards::GuardsInput::Expr instr, boolean branch,
1054+
IRGuards::Guards_v1::Guard g, IRGuards::GuardsInput::Expr instr, IRGuards::GuardValue gv,
10551055
int indirectionIndex
10561056
) {
10571057
exists(Node node |
10581058
nodeHasInstruction(node, instr, indirectionIndex) and
1059-
guardChecksNode(g, node, branch, indirectionIndex)
1059+
guardChecksNode(g, node, gv.asBooleanValue(), indirectionIndex)
10601060
)
10611061
}
10621062

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,10 @@ private module Cached {
568568

569569
cached // nothing is actually cached
570570
module BarrierGuard<guardChecksSig/3 guardChecks> {
571-
private predicate guardChecksAdjTypes(Guards::Guards_v3::Guard g, Expr e, boolean branch) {
572-
guardChecks(g, e, branch)
571+
private predicate guardChecksAdjTypes(
572+
Guards::Guards_v3::Guard g, Expr e, Guards::GuardValue gv
573+
) {
574+
guardChecks(g, e, gv.asBooleanValue())
573575
}
574576

575577
private predicate guardChecksWithWrappers(

shared/controlflow/codeql/controlflow/Guards.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,21 +1280,21 @@ module Make<
12801280
}
12811281
}
12821282

1283-
signature predicate guardChecksSig(Guard g, Expr e, boolean branch);
1283+
signature predicate guardChecksSig(Guard g, Expr e, GuardValue gv);
12841284

12851285
bindingset[this]
12861286
signature class StateSig;
12871287

12881288
private module WithState<StateSig State> {
1289-
signature predicate guardChecksSig(Guard g, Expr e, boolean branch, State state);
1289+
signature predicate guardChecksSig(Guard g, Expr e, GuardValue gv, State state);
12901290
}
12911291

12921292
/**
12931293
* Extends a `BarrierGuard` input predicate with wrapped invocations.
12941294
*/
12951295
module ValidationWrapper<guardChecksSig/3 guardChecks0> {
1296-
private predicate guardChecksWithState(Guard g, Expr e, boolean branch, Unit state) {
1297-
guardChecks0(g, e, branch) and exists(state)
1296+
private predicate guardChecksWithState(Guard g, Expr e, GuardValue gv, Unit state) {
1297+
guardChecks0(g, e, gv) and exists(state)
12981298
}
12991299

13001300
private module StatefulWrapper = ValidationWrapperWithState<Unit, guardChecksWithState/4>;
@@ -1366,7 +1366,7 @@ module Make<
13661366
* Holds if the guard `g` validates the expression `e` upon evaluating to `val`.
13671367
*/
13681368
private predicate guardChecks(Guard g, Expr e, GuardValue val, State state) {
1369-
guardChecks0(g, e, val.asBooleanValue(), state)
1369+
guardChecks0(g, e, val, state)
13701370
or
13711371
exists(NonOverridableMethodCall call, ParameterPosition ppos, ArgumentPosition apos |
13721372
g = call and

0 commit comments

Comments
 (0)