Skip to content

Commit 9df5e43

Browse files
committed
C++: Block flow through indirect flow through pointer-arithmetic instructions when following flow for the allocation size.
1 parent 5632dd5 commit 9df5e43

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/AllocationToInvalidPointer.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,20 @@ private module Config implements ProductFlow::StateConfigSig {
284284
pointerAddInstructionHasBounds0(_, allocSink, sizeSink, sizeAddend)
285285
}
286286

287+
private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate
288+
287289
predicate isBarrier2(DataFlow::Node node, FlowState2 state) {
288290
node = SizeBarrier::getABarrierNode(state)
289291
}
290292

293+
predicate isBarrier2(DataFlow::Node node) {
294+
exists(Operand operand, PointerAddInstruction add |
295+
node.(IndirectOperand).hasOperandAndIndirectionIndex(operand, _) and
296+
add.getLeftOperand() = operand and
297+
add.getRight().(ConstantInstruction).getValue() != "0"
298+
)
299+
}
300+
291301
predicate isBarrierIn1(DataFlow::Node node) { isSourcePair(node, _, _, _) }
292302

293303
predicate isBarrierOut2(DataFlow::Node node) {

0 commit comments

Comments
 (0)