Skip to content

Commit a40a393

Browse files
authored
Merge pull request github#7134 from aschackmull/java/additionalvaluestep
Java: Add support for adding additional value steps.
2 parents 6b7abac + 2fe6880 commit a40a393

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

java/ql/lib/semmle/code/java/dataflow/FlowSteps.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ class AdditionalTaintStep extends Unit {
6464
abstract predicate step(DataFlow::Node node1, DataFlow::Node node2);
6565
}
6666

67+
/**
68+
* A unit class for adding additional value steps.
69+
*
70+
* Extend this class to add additional value-preserving steps that should apply
71+
* to all data flow configurations.
72+
*/
73+
class AdditionalValueStep extends Unit {
74+
/**
75+
* Holds if the step from `node1` to `node2` is a value-preserving step and
76+
* should apply to all data flow configurations.
77+
*/
78+
abstract predicate step(DataFlow::Node node1, DataFlow::Node node2);
79+
}
80+
6781
/**
6882
* A method or constructor that preserves taint.
6983
*

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ private import DataFlowDispatch
55
private import semmle.code.java.controlflow.Guards
66
private import semmle.code.java.dataflow.SSA
77
private import ContainerFlow
8+
private import semmle.code.java.dataflow.FlowSteps
89
private import semmle.code.java.dataflow.FlowSummary
910
private import FlowSummaryImpl as FlowSummaryImpl
1011
import DataFlowNodes::Private
@@ -73,9 +74,14 @@ private predicate variableCaptureStep(Node node1, ExprNode node2) {
7374
* variable capture.
7475
*/
7576
predicate jumpStep(Node node1, Node node2) {
76-
staticFieldStep(node1, node2) or
77-
variableCaptureStep(node1, node2) or
77+
staticFieldStep(node1, node2)
78+
or
79+
variableCaptureStep(node1, node2)
80+
or
7881
variableCaptureStep(node1.(PostUpdateNode).getPreUpdateNode(), node2)
82+
or
83+
any(AdditionalValueStep a).step(node1, node2) and
84+
node1.getEnclosingCallable() != node2.getEnclosingCallable()
7985
}
8086

8187
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ predicate simpleLocalFlowStep(Node node1, Node node2) {
158158
)
159159
or
160160
FlowSummaryImpl::Private::Steps::summaryLocalStep(node1, node2, true)
161+
or
162+
any(AdditionalValueStep a).step(node1, node2) and
163+
pragma[only_bind_out](node1.getEnclosingCallable()) =
164+
pragma[only_bind_out](node2.getEnclosingCallable())
161165
}
162166

163167
private newtype TContent =

0 commit comments

Comments
 (0)