mirror of
https://github.com/github/codeql.git
synced 2025-12-22 19:56:32 +01:00
CPP: Add DataFlow to strdup.
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import semmle.code.cpp.models.interfaces.Allocation
|
||||
import semmle.code.cpp.models.interfaces.ArrayFunction
|
||||
import semmle.code.cpp.models.interfaces.DataFlow
|
||||
import semmle.code.cpp.models.interfaces.Taint
|
||||
|
||||
/**
|
||||
* A `strdup` style allocation function.
|
||||
*/
|
||||
class StrdupFunction extends AllocationFunction {
|
||||
class StrdupFunction extends AllocationFunction, ArrayFunction, DataFlowFunction {
|
||||
StrdupFunction() {
|
||||
exists(string name |
|
||||
hasGlobalOrStdName(name) and
|
||||
@@ -28,4 +31,15 @@ class StrdupFunction extends AllocationFunction {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override predicate hasArrayInput(int bufParam) { bufParam = 0 }
|
||||
|
||||
override predicate hasArrayWithNullTerminator(int bufParam) { bufParam = 0 }
|
||||
|
||||
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
|
||||
// These always copy the full value of the input buffer to the result
|
||||
// buffer
|
||||
input.isParameterDeref(0) and
|
||||
output.isReturnValueDeref()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user