Skip to content

Commit 1b9e375

Browse files
author
Robert Marsh
committed
C++: Move getACallArgumentOrIndirection
1 parent fd807d4 commit 1b9e375

2 files changed

Lines changed: 13 additions & 23 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/dataflow/DefaultTaintTracking.qll

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private predicate instructionTaintStep(Instruction i1, Instruction i2) {
163163
i2 = any(CallInstruction call |
164164
exists(int indexIn |
165165
modelTaintToReturnValue(call.getStaticCallTarget(), indexIn) and
166-
i1 = getACallArgumentOrIndirection(call, indexIn)
166+
i1 = DataFlow::getACallArgumentOrIndirection(call, indexIn)
167167
)
168168
)
169169
or
@@ -175,28 +175,13 @@ private predicate instructionTaintStep(Instruction i1, Instruction i2) {
175175
i2 = any(WriteSideEffectInstruction outNode |
176176
exists(CallInstruction call, int indexIn, int indexOut |
177177
modelTaintToParameter(call.getStaticCallTarget(), indexIn, indexOut) and
178-
i1 = getACallArgumentOrIndirection(call, indexIn) and
178+
i1 = DataFlow::getACallArgumentOrIndirection(call, indexIn) and
179179
outNode.getIndex() = indexOut and
180180
outNode.getPrimaryInstruction() = call
181181
)
182182
)
183183
}
184184

185-
/**
186-
* Get an instruction that goes into argument `argumentIndex` of `call`. This
187-
* can be either directly or through one pointer indirection.
188-
*/
189-
private Instruction getACallArgumentOrIndirection(CallInstruction call, int argumentIndex) {
190-
result = call.getPositionalArgument(argumentIndex)
191-
or
192-
exists(ReadSideEffectInstruction readSE |
193-
// TODO: why are read side effect operands imprecise?
194-
result = readSE.getSideEffectOperand().getAnyDef() and
195-
readSE.getPrimaryInstruction() = call and
196-
readSE.getIndex() = argumentIndex
197-
)
198-
}
199-
200185
private predicate modelTaintToParameter(Function f, int parameterIn, int parameterOut) {
201186
exists(FunctionInput modelIn, FunctionOutput modelOut |
202187
f.(TaintFunction).hasTaintFlow(modelIn, modelOut) and

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,15 @@ predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
265265
}
266266

267267
private predicate simpleInstructionLocalFlowStep(Instruction iFrom, Instruction iTo) {
268-
iTo.(CopyInstruction).getSourceValue() = iFrom or
269-
iTo.(PhiInstruction).getAnOperand().getDef() = iFrom or
268+
iTo.(CopyInstruction).getSourceValue() = iFrom
269+
or
270+
iTo.(PhiInstruction).getAnOperand().getDef() = iFrom
271+
or
270272
// Treat all conversions as flow, even conversions between different numeric types.
271-
iTo.(ConvertInstruction).getUnary() = iFrom or
272-
iTo.(InheritanceConversionInstruction).getUnary() = iFrom or
273+
iTo.(ConvertInstruction).getUnary() = iFrom
274+
or
275+
iTo.(InheritanceConversionInstruction).getUnary() = iFrom
276+
or
273277
// A chi instruction represents a point where a new value (the _partial_
274278
// operand) may overwrite an old value (the _total_ operand), but the alias
275279
// analysis couldn't determine that it surely will overwrite every bit of it or
@@ -283,7 +287,8 @@ private predicate simpleInstructionLocalFlowStep(Instruction iFrom, Instruction
283287
// for variables that have escaped: for soundness, the IR has to assume that
284288
// every write to an unknown address can affect every escaped variable, and
285289
// this assumption shows up as data flowing through partial chi operands.
286-
iTo.getAnOperand().(ChiTotalOperand).getDef() = iFrom or
290+
iTo.getAnOperand().(ChiTotalOperand).getDef() = iFrom
291+
or
287292
// Flow from argument to return value
288293
iTo = any(CallInstruction call |
289294
exists(int indexIn |
@@ -309,7 +314,7 @@ private predicate simpleInstructionLocalFlowStep(Instruction iFrom, Instruction
309314
* Get an instruction that goes into argument `argumentIndex` of `call`. This
310315
* can be either directly or through one pointer indirection.
311316
*/
312-
private Instruction getACallArgumentOrIndirection(CallInstruction call, int argumentIndex) {
317+
Instruction getACallArgumentOrIndirection(CallInstruction call, int argumentIndex) {
313318
result = call.getPositionalArgument(argumentIndex)
314319
or
315320
exists(ReadSideEffectInstruction readSE |

0 commit comments

Comments
 (0)