Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 507ada1

Browse files
committed
C++: Sort out the localFlow / simpleLocalFlow confusion (and the same for taint).
1 parent 8fbbc2b commit 507ada1

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,10 +1962,20 @@ cached
19621962
private module Cached {
19631963
/**
19641964
* Holds if data flows from `nodeFrom` to `nodeTo` in exactly one local
1965-
* (intra-procedural) step.
1965+
* (intra-procedural) step. This relation is only used for local dataflow
1966+
* (for example `DataFlow::localFlow(source, sink)`) so it contains
1967+
* special cases that should only apply to local dataflow.
19661968
*/
19671969
cached
1968-
predicate localFlowStep(Node nodeFrom, Node nodeTo) { simpleLocalFlowStep(nodeFrom, nodeTo) }
1970+
predicate localFlowStep(Node nodeFrom, Node nodeTo) {
1971+
// common dataflow steps
1972+
simpleLocalFlowStep(nodeFrom, nodeTo)
1973+
or
1974+
// models-as-data summarized flow for local data flow (i.e. special case for flow
1975+
// through calls to modelled functions, without relying on global dataflow to join
1976+
// the dots).
1977+
FlowSummaryImpl::Private::Steps::summaryThroughStepValue(nodeFrom, nodeTo, _)
1978+
}
19691979

19701980
private predicate indirectionOperandFlow(RawIndirectOperand nodeFrom, Node nodeTo) {
19711981
nodeFrom != nodeTo and
@@ -2031,8 +2041,9 @@ private module Cached {
20312041
/**
20322042
* INTERNAL: do not use.
20332043
*
2034-
* This is the local flow predicate that's used as a building block in global
2035-
* data flow. It may have less flow than the `localFlowStep` predicate.
2044+
* This is the local flow predicate that's used as a building block in both
2045+
* local and global data flow. It may have less flow than the `localFlowStep`
2046+
* predicate.
20362047
*/
20372048
cached
20382049
predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
@@ -2072,11 +2083,8 @@ private module Cached {
20722083
reverseFlow(nodeFrom, nodeTo)
20732084
or
20742085
// models-as-data summarized flow
2075-
FlowSummaryImpl::Private::Steps::summaryThroughStepValue(nodeFrom, nodeTo, _)
2076-
or
20772086
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom.(FlowSummaryNode).getSummaryNode(),
20782087
nodeTo.(FlowSummaryNode).getSummaryNode(), true)
2079-
// TODO: should these really be in the same place?
20802088
}
20812089

20822090
private predicate simpleInstructionLocalFlowStep(Operand opFrom, Instruction iTo) {

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ private import semmle.code.cpp.dataflow.internal.FlowSummaryImpl as FlowSummaryI
1010

1111
/**
1212
* Holds if taint propagates from `nodeFrom` to `nodeTo` in exactly one local
13-
* (intra-procedural) step.
13+
* (intra-procedural) step. This relation is only used for local taint flow
14+
* (for example `TaintTracking::localTaint(source, sink)`) so it may contain
15+
* special cases that should only apply to local taint flow.
1416
*/
1517
predicate localTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
18+
// dataflow step
1619
DataFlow::localFlowStep(nodeFrom, nodeTo)
1720
or
21+
// taint flow step
1822
localAdditionalTaintStep(nodeFrom, nodeTo)
23+
or
24+
// models-as-data summarized flow for local data flow (i.e. special case for flow
25+
// through calls to modelled functions, without relying on global dataflow to join
26+
// the dots).
27+
FlowSummaryImpl::Private::Steps::summaryThroughStepTaint(nodeFrom, nodeTo, _)
1928
}
2029

2130
/**
@@ -40,11 +49,8 @@ predicate localAdditionalTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeT
4049
any(Ssa::Indirection ind).isAdditionalTaintStep(nodeFrom, nodeTo)
4150
or
4251
// models-as-data summarized flow
43-
FlowSummaryImpl::Private::Steps::summaryThroughStepTaint(nodeFrom, nodeTo, _)
44-
or
4552
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom.(FlowSummaryNode).getSummaryNode(),
4653
nodeTo.(FlowSummaryNode).getSummaryNode(), false)
47-
// TODO: should these really be in the same place?
4854
}
4955

5056
/**

0 commit comments

Comments
 (0)