mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
30 lines
1.0 KiB
Plaintext
30 lines
1.0 KiB
Plaintext
import cpp
|
|
import semmle.code.cpp.security.InvalidPointerDereference.AllocationToInvalidPointer
|
|
import TestUtilities.InlineExpectationsTest
|
|
import semmle.code.cpp.ir.IR
|
|
import semmle.code.cpp.dataflow.new.DataFlow
|
|
|
|
module AllocationToInvalidPointerTest implements TestSig {
|
|
string getARelevantTag() { result = "alloc" }
|
|
|
|
predicate hasActualResult(Location location, string element, string tag, string value) {
|
|
exists(DataFlow::Node allocation, PointerAddInstruction pai, int delta |
|
|
pointerAddInstructionHasBounds(allocation, pai, _, delta) and
|
|
location = pai.getLocation() and
|
|
element = pai.toString() and
|
|
tag = "alloc"
|
|
|
|
|
delta > 0 and
|
|
value = "L" + allocation.getLocation().getStartLine().toString() + "+" + delta.toString()
|
|
or
|
|
delta = 0 and
|
|
value = "L" + allocation.getLocation().getStartLine().toString()
|
|
or
|
|
delta < 0 and
|
|
value = "L" + allocation.getLocation().getStartLine().toString() + "-" + (-delta).toString()
|
|
)
|
|
}
|
|
}
|
|
|
|
import MakeTest<AllocationToInvalidPointerTest>
|