Skip to content

Commit 0a4406d

Browse files
committed
Guards: Push forex-range constraint in.
1 parent 8624f9c commit 0a4406d

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

shared/controlflow/codeql/controlflow/Guards.qll

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,16 +1024,34 @@ module Make<
10241024
ReturnImplies::guardControls(call, val, _, _)
10251025
}
10261026

1027-
predicate relevantReturnValue(NonOverridableMethod m, GuardValue val) {
1027+
/**
1028+
* Holds if a call to `m` having a return value of `retval` is reachable
1029+
* by a chain of implications.
1030+
*/
1031+
predicate relevantReturnValue(NonOverridableMethod m, GuardValue retval) {
10281032
exists(NonOverridableMethodCall call |
1029-
relevantCallValue(call, val) and
1033+
relevantCallValue(call, retval) and
10301034
call.getMethod() = m and
1031-
not val instanceof TException
1035+
not retval instanceof TException
1036+
)
1037+
}
1038+
1039+
/**
1040+
* Holds if a call to `m` having a return value of `retval` is reachable
1041+
* by a chain of implications, and `ret` is a return expression in `m`
1042+
* that could possibly have the value `retval`.
1043+
*/
1044+
predicate relevantReturnExprValue(NonOverridableMethod m, ReturnExpr ret, GuardValue retval) {
1045+
relevantReturnValue(m, retval) and
1046+
ret = m.getAReturnExpr() and
1047+
not exists(GuardValue notRetval |
1048+
exprHasValue(ret, notRetval) and
1049+
disjointValues(notRetval, retval)
10321050
)
10331051
}
10341052

10351053
private predicate returnGuard(Guard guard, GuardValue val) {
1036-
relevantReturnValue(guard.(ReturnExpr).getMethod(), val)
1054+
relevantReturnExprValue(_, guard, val)
10371055
}
10381056

10391057
module ReturnImplies = ImpliesTC<returnGuard/2>;
@@ -1058,7 +1076,7 @@ module Make<
10581076
exists(Guard g0, GuardValue v0 |
10591077
directlyControlsReturn(g0, v0, ret) and
10601078
BranchImplies::ssaControls(param, val, g0, v0) and
1061-
relevantReturnValue(m, retval)
1079+
relevantReturnExprValue(m, ret, retval)
10621080
)
10631081
or
10641082
ReturnImplies::ssaControls(param, val, ret, retval)
@@ -1166,7 +1184,7 @@ module Make<
11661184
guardChecksDef(guard, param, val, state)
11671185
|
11681186
guard.valueControls(ret.getBasicBlock(), val) and
1169-
relevantReturnValue(m, retval)
1187+
relevantReturnExprValue(m, ret, retval)
11701188
or
11711189
ReturnImplies::guardControls(guard, val, ret, retval)
11721190
)

0 commit comments

Comments
 (0)