Skip to content

Commit 618bf2e

Browse files
committed
C++: IR data flow through total chi operands
1 parent 64c79bf commit 618bf2e

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,21 @@ private predicate simpleInstructionLocalFlowStep(Instruction iFrom, Instruction
265265
iTo.(PhiInstruction).getAnOperand().getDef() = iFrom or
266266
// Treat all conversions as flow, even conversions between different numeric types.
267267
iTo.(ConvertInstruction).getUnary() = iFrom or
268-
iTo.(InheritanceConversionInstruction).getUnary() = iFrom
268+
iTo.(InheritanceConversionInstruction).getUnary() = iFrom or
269+
// A chi instruction represents a point where a new value (the _partial_
270+
// operand) may overwrite an old value (the _total_ operand), but the alias
271+
// analysis couldn't determine that it surely will overwrite every bit of it or
272+
// that it surely will overwrite no bit of it.
273+
//
274+
// By allowing flow through the total operand, we ensure that flow is not lost
275+
// due to shortcomings of the alias analysis. We may get false flow in cases
276+
// where the data is indeed overwritten.
277+
//
278+
// Allowing flow through the partial operand would be more noisy, especially
279+
// for variables that have escaped: for soundness, the IR has to assume that
280+
// every write to an unknown address can affect every escaped variable, and
281+
// this assumption shows up as data flowing through partial chi operands.
282+
iTo.getAnOperand().(ChiTotalOperand).getDef() = iFrom
269283
}
270284

271285
/**

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@
2222
| taint.cpp:250:8:250:8 | taint.cpp:223:10:223:15 | AST only |
2323
| taint.cpp:256:8:256:8 | taint.cpp:223:10:223:15 | AST only |
2424
| taint.cpp:261:7:261:7 | taint.cpp:258:7:258:12 | AST only |
25-
| taint.cpp:350:7:350:7 | taint.cpp:330:6:330:11 | AST only |
2625
| taint.cpp:351:7:351:7 | taint.cpp:330:6:330:11 | AST only |
2726
| taint.cpp:352:7:352:7 | taint.cpp:330:6:330:11 | AST only |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
| taint.cpp:290:7:290:7 | x | taint.cpp:275:6:275:11 | call to source |
1515
| taint.cpp:291:7:291:7 | y | taint.cpp:275:6:275:11 | call to source |
1616
| taint.cpp:337:7:337:7 | t | taint.cpp:330:6:330:11 | call to source |
17+
| taint.cpp:350:7:350:7 | t | taint.cpp:330:6:330:11 | call to source |

0 commit comments

Comments
 (0)