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

Skip to content

Commit 3aa2932

Browse files
committed
C++: Ensure that only non-conflated chi instructions are used everywhere
1 parent 317734f commit 3aa2932

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ abstract class PostUpdateNode extends InstructionNode {
245245
* setY(&x); // a partial definition of the object `x`.
246246
* ```
247247
*/
248-
abstract class PartialDefinitionNode extends PostUpdateNode, TInstructionNode {}
248+
abstract class PartialDefinitionNode extends PostUpdateNode, TInstructionNode { }
249249

250250
private class ExplicitFieldStoreQualifierNode extends PartialDefinitionNode {
251251
override ChiInstruction instr;
@@ -276,13 +276,13 @@ class DefinitionByReferenceNode extends PartialDefinitionNode {
276276
CallInstruction call;
277277

278278
DefinitionByReferenceNode() {
279+
not instr.isResultConflated() and
279280
instr.getPartial() = write and
280-
call = write.getPrimaryInstruction() }
281-
282-
override Node getPreUpdateNode() {
283-
result.asInstruction() = instr.getTotal()
281+
call = write.getPrimaryInstruction()
284282
}
285283

284+
override Node getPreUpdateNode() { result.asInstruction() = instr.getTotal() }
285+
286286
/** Gets the argument corresponding to this node. */
287287
Expr getArgument() {
288288
result = call.getPositionalArgument(write.getIndex()).getUnconvertedResultExpression()
@@ -292,9 +292,7 @@ class DefinitionByReferenceNode extends PartialDefinitionNode {
292292
}
293293

294294
/** Gets the parameter through which this value is assigned. */
295-
Parameter getParameter() {
296-
exists(CallInstruction ci | result = ci.getStaticCallTarget().getParameter(write.getIndex()))
297-
}
295+
Parameter getParameter() { result = call.getStaticCallTarget().getParameter(write.getIndex()) }
298296
}
299297

300298
/**
@@ -383,6 +381,7 @@ predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
383381
simpleInstructionLocalFlowStep(nodeFrom.asInstruction(), nodeTo.asInstruction())
384382
or
385383
exists(LoadInstruction load, ChiInstruction chi |
384+
not chi.isResultConflated() and
386385
nodeTo.asInstruction() = load and
387386
nodeFrom.asInstruction() = chi and
388387
load.getSourceValueOperand().getAnyDef() = chi
@@ -412,11 +411,10 @@ private predicate simpleInstructionLocalFlowStep(Instruction iFrom, Instruction
412411
//
413412
// Flow through the partial operand belongs in the taint-tracking libraries
414413
// for now.
415-
416414
// TODO: To capture flow from a partial definition of an object (i.e., a field write) to the object
417415
// we add dataflow through partial chi operands, but only if the chi node is not the chi node for all
418416
// aliased memory.
419-
iTo.getAnOperand().(ChiPartialOperand).getDef() = iFrom and not iFrom.isResultConflated()
417+
iTo.getAnOperand().(ChiPartialOperand).getDef() = iFrom and not iTo.isResultConflated()
420418
or
421419
iTo.getAnOperand().(ChiTotalOperand).getDef() = iFrom
422420
or

0 commit comments

Comments
 (0)