mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
C++: Prune the set of interesting pointer-arithmetic instructions by another flow.
This commit is contained in:
@@ -241,6 +241,7 @@ pragma[nomagic]
|
|||||||
predicate pointerAddInstructionHasBounds(
|
predicate pointerAddInstructionHasBounds(
|
||||||
PointerAddInstruction pai, DataFlow::Node sink1, DataFlow::Node sink2, int delta
|
PointerAddInstruction pai, DataFlow::Node sink1, DataFlow::Node sink2, int delta
|
||||||
) {
|
) {
|
||||||
|
InterestingPointerAddInstruction::isInteresting(pragma[only_bind_into](pai)) and
|
||||||
exists(Instruction right, Instruction instr2 |
|
exists(Instruction right, Instruction instr2 |
|
||||||
pai.getRight() = right and
|
pai.getRight() = right and
|
||||||
pai.getLeft() = sink1.asInstruction() and
|
pai.getLeft() = sink1.asInstruction() and
|
||||||
@@ -251,6 +252,29 @@ predicate pointerAddInstructionHasBounds(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module InterestingPointerAddInstruction {
|
||||||
|
private module PointerAddInstructionConfig implements DataFlow::ConfigSig {
|
||||||
|
predicate isSource(DataFlow::Node source) {
|
||||||
|
// The sources is the same as in the sources for the second
|
||||||
|
// projection in the `AllocToInvalidPointerConfig` module.
|
||||||
|
hasSize(source.asConvertedExpr(), _, _)
|
||||||
|
}
|
||||||
|
|
||||||
|
predicate isSink(DataFlow::Node sink) {
|
||||||
|
sink.asInstruction() = any(PointerAddInstruction pai).getLeft()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private import DataFlow::Global<PointerAddInstructionConfig>
|
||||||
|
|
||||||
|
predicate isInteresting(PointerAddInstruction pai) {
|
||||||
|
exists(DataFlow::Node n |
|
||||||
|
n.asInstruction() = pai.getLeft() and
|
||||||
|
flowTo(n)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds if `pai` is non-strictly upper bounded by `sink2 + delta` and `sink1` is the
|
* Holds if `pai` is non-strictly upper bounded by `sink2 + delta` and `sink1` is the
|
||||||
* left operand of the pointer-arithmetic operation.
|
* left operand of the pointer-arithmetic operation.
|
||||||
|
|||||||
Reference in New Issue
Block a user