Skip to content

Commit 9e0d6e8

Browse files
committed
C++: move taint step cases to TaintTrackingUtil
1 parent 52b1fb7 commit 9e0d6e8

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ private import semmle.code.cpp.ir.IR
22
private import semmle.code.cpp.ir.dataflow.DataFlow
33
private import ModelUtil
44
private import semmle.code.cpp.models.interfaces.DataFlow
5+
private import semmle.code.cpp.models.interfaces.SideEffect
56

67
/**
78
* Holds if taint propagates from `nodeFrom` to `nodeTo` in exactly one local
@@ -49,6 +50,23 @@ private predicate localInstructionTaintStep(Instruction nodeFrom, Instruction no
4950
nodeTo.(LoadInstruction).getSourceAddress() = nodeFrom
5051
or
5152
modeledInstructionTaintStep(nodeFrom, nodeTo)
53+
or
54+
// Flow through partial reads of arrays and unions
55+
nodeTo.(LoadInstruction).getSourceValueOperand().getAnyDef() = nodeFrom and
56+
not nodeFrom.isResultConflated() and
57+
(
58+
nodeFrom.getResultType() instanceof ArrayType or
59+
nodeFrom.getResultType() instanceof Union
60+
)
61+
or
62+
// Flow from an element to an array or union that contains it.
63+
nodeTo.(ChiInstruction).getPartial() = nodeFrom and
64+
not nodeTo.isResultConflated() and
65+
exists(Type t | nodeTo.getResultLanguageType().hasType(t, false) |
66+
t instanceof Union
67+
or
68+
t instanceof ArrayType
69+
)
5270
}
5371

5472
/**
@@ -104,7 +122,10 @@ predicate modeledInstructionTaintStep(Instruction instrIn, Instruction instrOut)
104122
// could model this flow in two separate steps, but that would add reverse
105123
// flow from the write side-effect to the call instruction, which may not be
106124
// desirable.
107-
exists(CallInstruction call, Function func, FunctionInput modelIn, OutParameterDeref modelMidOut, int indexMid, InParameter modelMidIn, OutReturnValue modelOut |
125+
exists(
126+
CallInstruction call, Function func, FunctionInput modelIn, OutParameterDeref modelMidOut,
127+
int indexMid, InParameter modelMidIn, OutReturnValue modelOut
128+
|
108129
instrIn = callInput(call, modelIn) and
109130
instrOut = callOutput(call, modelOut) and
110131
call.getStaticCallTarget() = func and

cpp/ql/test/library-tests/dataflow/taint-tests/test_diff.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
| taint.cpp:93:11:93:11 | taint.cpp:71:22:71:27 | AST only |
2323
| taint.cpp:94:11:94:11 | taint.cpp:72:7:72:12 | AST only |
2424
| taint.cpp:109:7:109:13 | taint.cpp:105:12:105:17 | IR only |
25+
| taint.cpp:110:7:110:13 | taint.cpp:105:12:105:17 | IR only |
26+
| taint.cpp:111:7:111:13 | taint.cpp:106:12:106:17 | IR only |
27+
| taint.cpp:112:7:112:13 | taint.cpp:106:12:106:17 | IR only |
2528
| taint.cpp:130:7:130:9 | taint.cpp:127:8:127:13 | IR only |
2629
| taint.cpp:137:7:137:9 | taint.cpp:120:11:120:16 | AST only |
2730
| taint.cpp:173:8:173:13 | taint.cpp:164:19:164:24 | AST only |

cpp/ql/test/library-tests/dataflow/taint-tests/test_ir.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
| taint.cpp:16:8:16:14 | source1 | taint.cpp:12:22:12:27 | call to source |
55
| taint.cpp:17:8:17:16 | ++ ... | taint.cpp:12:22:12:27 | call to source |
66
| taint.cpp:109:7:109:13 | access to array | taint.cpp:105:12:105:17 | call to source |
7+
| taint.cpp:110:7:110:13 | access to array | taint.cpp:105:12:105:17 | call to source |
8+
| taint.cpp:111:7:111:13 | access to array | taint.cpp:106:12:106:17 | call to source |
9+
| taint.cpp:112:7:112:13 | access to array | taint.cpp:106:12:106:17 | call to source |
710
| taint.cpp:129:7:129:9 | * ... | taint.cpp:120:11:120:16 | call to source |
811
| taint.cpp:130:7:130:9 | * ... | taint.cpp:127:8:127:13 | call to source |
912
| taint.cpp:134:7:134:9 | * ... | taint.cpp:120:11:120:16 | call to source |

0 commit comments

Comments
 (0)