Skip to content

Commit f0b2aac

Browse files
committed
C++/Docs: add isAdditionalTaintStep to example
1 parent 9e84554 commit f0b2aac

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

docs/language/learn-ql/cpp/dataflow.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ The following data flow configuration tracks data flow from environment variable
244244
select fopen, "This 'fopen' uses data from $@.",
245245
getenv, "call to 'getenv'"
246246
247-
The following taint tracking configuration tracks data from a call to ``ntohl`` to an array index operation. It uses the ``Guards`` library to recognize expressions that have been bounds checked and avoid propagating taint through them.
247+
The following taint tracking configuration tracks data from a call to ``ntohl`` to an array index operation. It uses the ``Guards`` library to recognize expressions that have been bounds checked and avoid propagating taint through them. It also uses ``isAdditionalTaintStep`` to add flow from loop bounds to loop indexes.
248248

249249
.. code-block:: ql
250250
251251
import cpp
252252
import semmle.code.cpp.controlflow.Guards
253253
import semmle.code.cpp.dataflow.TaintTracking
254254
255-
class NetworkToBufferSizeConfiguration extends DataFlow::Configuration {
255+
class NetworkToBufferSizeConfiguration extends TaintTracking::Configuration {
256256
NetworkToBufferSizeConfiguration() { this = "NetworkToBufferSizeConfiguration" }
257257
258258
override predicate isSource(DataFlow::Node node) {
@@ -263,7 +263,15 @@ The following taint tracking configuration tracks data from a call to ``ntohl``
263263
exists(ArrayExpr ae | node.asExpr() = ae.getArrayOffset())
264264
}
265265
266-
override predicate isBarrier(DataFlow::Node node) {
266+
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
267+
exists(Loop loop, LoopCounter lc |
268+
loop = lc.getALoop() and
269+
loop.getControllingExpr().(RelationalOperation).getGreaterOperand() = pred.asExpr() |
270+
succ.asExpr() = lc.getVariableAccessInLoop(loop)
271+
)
272+
}
273+
274+
override predicate isSanitizer(DataFlow::Node node) {
267275
exists(GuardCondition gc, Variable v |
268276
gc.getAChild*() = v.getAnAccess() and
269277
node.asExpr() = v.getAnAccess() and

0 commit comments

Comments
 (0)